Bug 1403224 - Add tests for MatchPattern.subsumes(). r=aswan
authorIan Moody <moz-ian@perix.co.uk>
Tue, 26 Sep 2017 19:36:32 +0100
changeset 385882 ce6d10ff76ab44d362fc527d627cce614dfbf37e
parent 385881 2e1d10cef14545d18fb7976cc81fd7433c49cc63
child 385883 2ab5ef946a409ab40306ad0e54a89c75081ffd9c
push id32672
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 09:00:05 +0000
treeherdermozilla-central@3efcb26e5f37 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1403224
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1403224 - Add tests for MatchPattern.subsumes(). r=aswan MozReview-Commit-ID: 8Wi4d4BVApq
toolkit/components/extensions/test/xpcshell/test_MatchPattern.js
--- a/toolkit/components/extensions/test/xpcshell/test_MatchPattern.js
+++ b/toolkit/components/extensions/test/xpcshell/test_MatchPattern.js
@@ -221,8 +221,59 @@ add_task(async function test_MatchGlob()
   pass({url: moz, pattern: ["*.org/"]});
   fail({url: moz, pattern: ["*.org"]});
 
   // Wrong TLD
   fail({url: moz, pattern: ["*oz*.com/"]});
   // Case sensitive
   fail({url: moz, pattern: ["*.ORG/"]});
 });
+
+add_task(async function test_MatchPattern_subsumes() {
+  function test(oldPat, newPat) {
+    let m = new MatchPatternSet(oldPat);
+    return m.subsumes(new MatchPattern(newPat));
+  }
+
+  function pass({oldPat, newPat}) {
+    ok(test(oldPat, newPat), `${JSON.stringify(oldPat)} subsumes "${newPat}"`);
+  }
+
+  function fail({oldPat, newPat}) {
+    ok(!test(oldPat, newPat), `${JSON.stringify(oldPat)} doesn't subsume "${newPat}"`);
+  }
+
+  pass({oldPat: ["<all_urls>"], newPat: "*://*/*"});
+  pass({oldPat: ["<all_urls>"], newPat: "http://*/*"});
+  pass({oldPat: ["<all_urls>"], newPat: "http://*.example.com/*"});
+
+  pass({oldPat: ["*://*/*"], newPat: "http://*/*"});
+  pass({oldPat: ["*://*/*"], newPat: "wss://*/*"});
+  pass({oldPat: ["*://*/*"], newPat: "http://*.example.com/*"});
+
+  pass({oldPat: ["*://*.example.com/*"], newPat: "http://*.example.com/*"});
+  pass({oldPat: ["*://*.example.com/*"], newPat: "*://sub.example.com/*"});
+
+  pass({oldPat: ["https://*/*"], newPat: "https://*.example.com/*"});
+  pass({oldPat: ["http://*.example.com/*"], newPat: "http://subdomain.example.com/*"});
+  pass({oldPat: ["http://*.sub.example.com/*"], newPat: "http://sub.example.com/*"});
+  pass({oldPat: ["http://*.sub.example.com/*"], newPat: "http://sec.sub.example.com/*"});
+  pass({oldPat: ["http://www.example.com/*"], newPat: "http://www.example.com/path/*"});
+  pass({oldPat: ["http://www.example.com/path/*"], newPat: "http://www.example.com/*"});
+
+  fail({oldPat: ["*://*/*"], newPat: "<all_urls>"});
+  fail({oldPat: ["*://*/*"], newPat: "ftp://*/*"});
+  fail({oldPat: ["*://*/*"], newPat: "file://*/*"});
+
+  fail({oldPat: ["http://example.com/*"], newPat: "*://example.com/*"});
+  fail({oldPat: ["http://example.com/*"], newPat: "https://example.com/*"});
+  fail({oldPat: ["http://example.com/*"], newPat: "http://otherexample.com/*"});
+  fail({oldPat: ["http://example.com/*"], newPat: "http://*.example.com/*"});
+  fail({oldPat: ["http://example.com/*"], newPat: "http://subdomain.example.com/*"});
+
+  fail({oldPat: ["http://subdomain.example.com/*"], newPat: "http://example.com/*"});
+  fail({oldPat: ["http://subdomain.example.com/*"], newPat: "http://*.example.com/*"});
+  fail({oldPat: ["http://sub.example.com/*"], newPat: "http://*.sub.example.com/*"});
+
+  fail({oldPat: ["ws://example.com/*"], newPat: "wss://example.com/*"});
+  fail({oldPat: ["http://example.com/*"], newPat: "ws://example.com/*"});
+  fail({oldPat: ["https://example.com/*"], newPat: "wss://example.com/*"});
+});