addon-sdk/source/test/test-match-pattern.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4 "use strict";
     6 const { MatchPattern } = require("sdk/util/match-pattern");
     8 exports.testMatchPatternTestTrue = function(assert) {
     9   function ok(pattern, url) {
    10     let mp = new MatchPattern(pattern);
    11     assert.ok(mp.test(url), pattern + " should match " + url);
    12   }
    14   ok("*", "http://example.com");
    15   ok("*", "https://example.com");
    16   ok("*", "ftp://example.com");
    18   ok("*.example.com", "http://example.com");
    19   ok("*.example.com", "http://hamburger.example.com");
    20   ok("*.example.com", "http://hotdog.hamburger.example.com");
    22   ok("http://example.com*", "http://example.com");
    23   ok("http://example.com*", "http://example.com/");
    24   ok("http://example.com/*", "http://example.com/");
    25   ok("http://example.com/*", "http://example.com/potato-salad");
    26   ok("http://example.com/pickles/*", "http://example.com/pickles/");
    27   ok("http://example.com/pickles/*", "http://example.com/pickles/lemonade");
    29   ok("http://example.com", "http://example.com");
    30   ok("http://example.com/ice-cream", "http://example.com/ice-cream");
    32   ok(/.*zilla.*/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
    33   ok(/https:.*zilla.*/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
    34   ok('*.sample.com', 'http://ex.sample.com/foo.html');
    35   ok('*.amp.le.com', 'http://ex.amp.le.com');
    37   ok('data:*', 'data:text/html;charset=utf-8,');
    38 };
    40 exports.testMatchPatternTestFalse = function(assert) {
    41   function ok(pattern, url) {
    42     let mp = new MatchPattern(pattern);
    43     assert.ok(!mp.test(url), pattern + " should not match " + url);
    44   }
    46   ok("*", null);
    47   ok("*", "");
    48   ok("*", "bogus");
    49   ok("*", "chrome://browser/content/browser.xul");
    50   ok("*", "nttp://example.com");
    52   ok("*.example.com", null);
    53   ok("*.example.com", "");
    54   ok("*.example.com", "bogus");
    55   ok("*.example.com", "http://example.net");
    56   ok("*.example.com", "http://foo.com");
    57   ok("*.example.com", "http://example.com.foo");
    58   ok("*.example2.com", "http://example.com");
    60   ok("http://example.com/*", null);
    61   ok("http://example.com/*", "");
    62   ok("http://example.com/*", "bogus");
    63   ok("http://example.com/*", "http://example.com");
    64   ok("http://example.com/*", "http://foo.com/");
    66   ok("http://example.com", null);
    67   ok("http://example.com", "");
    68   ok("http://example.com", "bogus");
    69   ok("http://example.com", "http://example.com/");
    71   ok(/zilla.*/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
    72   ok(/.*zilla/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
    73   ok(/.*Zilla.*/, "https://bugzilla.redhat.com/show_bug.cgi?id=655464"); // bug 655464
    74   ok(/https:.*zilla/, "https://bugzilla.redhat.com/show_bug.cgi?id=569753");
    76   // bug 856913
    77   ok('*.ign.com', 'http://www.design.com');
    78   ok('*.ign.com', 'http://design.com');
    79   ok('*.zilla.com', 'http://bugzilla.mozilla.com');
    80   ok('*.zilla.com', 'http://mo-zilla.com');
    81   ok('*.amp.le.com', 'http://amp-le.com');
    82   ok('*.amp.le.com', 'http://examp.le.com');
    83 };
    85 exports.testMatchPatternErrors = function(assert) {
    86   assert.throws(
    87     function() new MatchPattern("*.google.com/*"),
    88     /There can be at most one/,
    89     "MatchPattern throws when supplied multiple '*'"
    90   );
    92   assert.throws(
    93     function() new MatchPattern("google.com"),
    94     /expected to be either an exact URL/,
    95     "MatchPattern throws when the wildcard doesn't use '*' and doesn't " +
    96     "look like a URL"
    97   );
    99   assert.throws(
   100     function() new MatchPattern("http://google*.com"),
   101     /expected to be the first or the last/,
   102     "MatchPattern throws when a '*' is in the middle of the wildcard"
   103   );
   105   assert.throws(
   106     function() new MatchPattern(/ /g),
   107     /^A RegExp match pattern cannot be set to `global` \(i\.e\. \/\/g\)\.$/,
   108     "MatchPattern throws on a RegExp set to `global` (i.e. //g)."
   109   );
   111   assert.throws(
   112     function() new MatchPattern(/ /i),
   113     /^A RegExp match pattern cannot be set to `ignoreCase` \(i\.e\. \/\/i\)\.$/,
   114     "MatchPattern throws on a RegExp set to `ignoreCase` (i.e. //i)."
   115   );
   117   assert.throws(
   118     function() new MatchPattern( / /m ),
   119     /^A RegExp match pattern cannot be set to `multiline` \(i\.e\. \/\/m\)\.$/,
   120     "MatchPattern throws on a RegExp set to `multiline` (i.e. //m)."
   121   );
   122 };
   124 exports.testMatchPatternInternals = function(assert) {
   125   assert.equal(
   126     new MatchPattern("http://google.com/test").exactURL,
   127     "http://google.com/test"
   128   );
   130   assert.equal(
   131     new MatchPattern("http://google.com/test/*").urlPrefix,
   132     "http://google.com/test/"
   133   );
   135   assert.equal(
   136     new MatchPattern("*.example.com").domain,
   137     "example.com"
   138   );
   139 };
   141 require('sdk/test').run(exports);

mercurial