Bug 460328: Make online whitelist entries match by prefix. r=dcamp, sr=biesi
authorHonza Bambas <honzab@allpeers.com>
Wed, 05 Nov 2008 16:01:08 -0800
changeset 21368 3502bada8a5c926d441fd061bd5d5330dca1cb4d
parent 21367 038df99ac499a5ad4011fb33a9b425336d104bf0
child 21369 ee04803822c96ba6505ee235331231d098f454e6
push id3509
push userdcamp@mozilla.com
push dateThu, 06 Nov 2008 00:07:27 +0000
treeherdermozilla-central@ee04803822c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdcamp, biesi
bugs460328
milestone1.9.1b2pre
Bug 460328: Make online whitelist entries match by prefix. r=dcamp, sr=biesi
dom/tests/mochitest/ajax/offline/Makefile.in
dom/tests/mochitest/ajax/offline/bypass.cacheManifest
dom/tests/mochitest/ajax/offline/bypass.cacheManifest^headers^
dom/tests/mochitest/ajax/offline/bypass.html
dom/tests/mochitest/ajax/offline/namespace1/Makefile.in
dom/tests/mochitest/ajax/offline/namespace1/script.js
dom/tests/mochitest/ajax/offline/namespace1/sub/Makefile.in
dom/tests/mochitest/ajax/offline/namespace1/sub/script1.js
dom/tests/mochitest/ajax/offline/namespace1/sub2/Makefile.in
dom/tests/mochitest/ajax/offline/namespace1/sub2/script2.js
dom/tests/mochitest/ajax/offline/namespace2/Makefile.in
dom/tests/mochitest/ajax/offline/namespace2/script3.js
dom/tests/mochitest/ajax/offline/test_bypass.html
netwerk/cache/src/nsDiskCacheDeviceSQL.cpp
--- a/dom/tests/mochitest/ajax/offline/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/Makefile.in
@@ -38,24 +38,25 @@
 DEPTH		= ../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/offline
 
 include $(DEPTH)/config/autoconf.mk
 
-DIRS = namespace1
+DIRS = namespace1 namespace2
 
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES	= \
 	offlineTests.js \
 	test_badManifestMagic.html \
 	test_badManifestMime.html \
+	test_bypass.html \
 	test_missingFile.html \
 	test_noManifest.html \
 	test_simpleManifest.html \
 	test_identicalManifest.html \
 	test_changingManifest.html \
 	test_refetchManifest.html \
 	test_offlineIFrame.html \
 	test_bug445544.html \
@@ -66,16 +67,19 @@ include $(topsrcdir)/config/rules.mk
 	test_bug460353.html \
 	460353_iframe_nomanifest.html \
 	460353_iframe_ownmanifest.html \
 	460353_iframe_samemanifest.html \
 	test_obsolete.html \
 	obsolete.html \
 	badManifestMagic.cacheManifest \
 	badManifestMagic.cacheManifest^headers^ \
+	bypass.cacheManifest \
+	bypass.cacheManifest^headers^ \
+	bypass.html \
 	fallback.html \
 	fallback2.html \
 	fallbackTop.html \
 	fallback.cacheManifest \
 	fallback.cacheManifest^headers^ \
 	foreign1.cacheManifest \
 	foreign1.cacheManifest^headers^ \
 	foreign2.cacheManifest \
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/bypass.cacheManifest
@@ -0,0 +1,7 @@
+CACHE MANIFEST
+
+bypass.html
+
+NETWORK:
+namespace1/sub
+namespace2
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/bypass.cacheManifest^headers^
@@ -0,0 +1,2 @@
+Content-Type: text/cache-manifest
+
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/bypass.html
@@ -0,0 +1,42 @@
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="bypass.cacheManifest">
+<head>
+
+<script type="text/javascript" src="namespace1/script.js"></script>
+<script type="text/javascript" src="namespace1/sub/script1.js"></script>
+<script type="text/javascript" src="namespace1/sub2/script2.js"></script>
+<script type="text/javascript" src="namespace2/script3.js"></script>
+
+<script class="testbody" type="text/javascript">
+
+function testScriptPresence(scriptPath, func, shouldPass)
+{
+  var msg = "Script " + scriptPath + (shouldPass ? " loaded" : " not loaded");
+  try {
+    eval(func);
+    opener.OfflineTest.ok(shouldPass, msg);
+  }
+  catch(ex) {
+    opener.OfflineTest.ok(!shouldPass, msg);
+  }
+
+}
+
+function startTest()
+{
+  testScriptPresence("namespace1/script.js", "scriptNo0Function();", false);
+  testScriptPresence("namespace1/sub/script1.js", "scriptNo1Function();", true);
+  testScriptPresence("namespace1/sub2/script2.js", "scriptNo2Function();", true);
+  testScriptPresence("namespace2/script3.js", "scriptNo3Function();", true);
+
+  opener.OfflineTest.teardown();
+  opener.OfflineTest.finish();
+  window.close(window);
+}
+
+</script>
+
+</head>
+
+<body onload="startTest();">
+</body>
+</html>
--- a/dom/tests/mochitest/ajax/offline/namespace1/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/namespace1/Makefile.in
@@ -38,17 +38,17 @@
 DEPTH		= ../../../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/offline/namespace1
 
 include $(DEPTH)/config/autoconf.mk
 
-DIRS = sub
+DIRS = sub sub2
 
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES	= \
         opp.html \
         $(NULL)
 
 libs::	$(_TEST_FILES)
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/namespace1/script.js
@@ -0,0 +1,4 @@
+function scriptNo0Function()
+{
+  return true;
+}
--- a/dom/tests/mochitest/ajax/offline/namespace1/sub/Makefile.in
+++ b/dom/tests/mochitest/ajax/offline/namespace1/sub/Makefile.in
@@ -42,12 +42,13 @@ VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/ajax/offline/namespace1/sub
 
 include $(DEPTH)/config/autoconf.mk
 
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES	= \
         opp.html \
+        script1.js \
         $(NULL)
 
 libs::	$(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/namespace1/sub/script1.js
@@ -0,0 +1,4 @@
+function scriptNo1Function()
+{
+  return true;
+}
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/namespace1/sub2/Makefile.in
@@ -0,0 +1,53 @@
+#
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is mozilla.org code.
+#
+# The Initial Developer of the Original Code is
+# Mozilla Foundation.
+# Portions created by the Initial Developer are Copyright (C) 2007
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either of the GNU General Public License Version 2 or later (the "GPL"),
+# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+DEPTH		= ../../../../../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+relativesrcdir	= dom/tests/mochitest/ajax/offline/namespace1/sub2
+
+include $(DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/rules.mk
+
+_TEST_FILES	= \
+        script2.js \
+        $(NULL)
+
+libs::	$(_TEST_FILES)
+	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/namespace1/sub2/script2.js
@@ -0,0 +1,4 @@
+function scriptNo2Function()
+{
+  return true;
+}
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/namespace2/Makefile.in
@@ -0,0 +1,53 @@
+#
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is mozilla.org code.
+#
+# The Initial Developer of the Original Code is
+# Mozilla Foundation.
+# Portions created by the Initial Developer are Copyright (C) 2007
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either of the GNU General Public License Version 2 or later (the "GPL"),
+# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+DEPTH		= ../../../../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+relativesrcdir	= dom/tests/mochitest/ajax/offline/namespace2
+
+include $(DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/rules.mk
+
+_TEST_FILES	= \
+        script3.js \
+        $(NULL)
+
+libs::	$(_TEST_FILES)
+	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/namespace2/script3.js
@@ -0,0 +1,4 @@
+function scriptNo3Function()
+{
+  return true;
+}
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/ajax/offline/test_bypass.html
@@ -0,0 +1,38 @@
+<html xmlns="http://www.w3.org/1999/xhtml" manifest="bypass.cacheManifest">
+<head>
+<title>Bypass test</title>
+
+<script type="text/javascript" src="/MochiKit/packed.js"></script>
+<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+
+<script class="testbody" type="text/javascript">
+
+/**
+ * This test defines manifest with namespace1/sub2 and namespace2 as bypass
+ * namespaces.
+ * When cache update finishes it loads a test body in an iframe. This iframe
+ * refers four js scripts, some matching the namespace to bypass and some not.
+ * Then checks that just expected scripts loads by calling a method of each
+ * of the script.
+ */
+
+SimpleTest.waitForExplicitFinish();
+
+if (OfflineTest.setup()) {
+  // Load test body when cache update process finished. The test itself
+  // continues at that file.
+  applicationCache.oncached = function()
+  {
+    window.open("bypass.html");
+  }
+}
+
+</script>
+
+</head>
+
+<body>
+</body>
+</html>
--- a/netwerk/cache/src/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/src/nsDiskCacheDeviceSQL.cpp
@@ -1765,51 +1765,39 @@ nsOfflineCacheDevice::GetMatchingNamespa
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool hasRows;
   rv = statement->ExecuteStep(&hasRows);
   NS_ENSURE_SUCCESS(rv, rv);
 
   *out = nsnull;
 
-  while (hasRows)
+  if (hasRows)
   {
     nsCString namespaceSpec;
     rv = statement->GetUTF8String(0, namespaceSpec);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCString data;
     rv = statement->GetUTF8String(1, data);
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRInt32 itemType;
     rv = statement->GetInt32(2, &itemType);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    // XXX: There is currently a proposal on the table to extend matching
-    // semantics for bypass entries to be a namespace (possibly with extra
-    // filter data).  When/if that happens, this logic will need to change.
-    if ((itemType & nsIApplicationCacheNamespace::NAMESPACE_BYPASS) &&
-        (namespaceSpec != key)) {
-      rv = statement->ExecuteStep(&hasRows);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      continue;
-    }
-
     nsCOMPtr<nsIApplicationCacheNamespace> ns =
       new nsApplicationCacheNamespace();
     if (!ns)
       return NS_ERROR_OUT_OF_MEMORY;
 
     rv = ns->Init(itemType, namespaceSpec, data);
     NS_ENSURE_SUCCESS(rv, rv);
 
     ns.swap(*out);
-    return NS_OK;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsOfflineCacheDevice::CacheOpportunistically(const nsCString &clientID,
                                              const nsACString &key)