aboutsummaryrefslogtreecommitdiff
path: root/www/waterfox/files/patch-bug1410634
blob: 0fdc6cbe00ca5f2c9a2f5fa11fe0db248c097146 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
commit a34cf3c8ad18
Author: Ben Kelly <ben@wanderview.com>
Date:   Tue Oct 24 09:24:53 2017 -0400

    Bug 1410634 - Part 1: Call channel IsFromCache() during OnStartRequest() to determine if update result came from http cache or network. r=tt, a=ritu
    
    --HG--
    extra : source : 087e11c956e368c41e91bdc5d689d5e94f3ef7ef
---
 dom/workers/ServiceWorkerScriptCache.cpp | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git dom/workers/ServiceWorkerScriptCache.cpp dom/workers/ServiceWorkerScriptCache.cpp
index a065a6fafbf8..f30bca95229c 100644
--- dom/workers/ServiceWorkerScriptCache.cpp
+++ dom/workers/ServiceWorkerScriptCache.cpp
@@ -100,12 +100,13 @@ public:
                  bool aIsMainScript)
     : mManager(aManager)
     , mRegistration(aRegistration)
-    , mIsMainScript(aIsMainScript)
     , mInternalHeaders(new InternalHeaders())
     , mLoadFlags(nsIChannel::LOAD_BYPASS_SERVICE_WORKER)
     , mState(WaitingForInitialization)
     , mNetworkResult(NS_OK)
     , mCacheResult(NS_OK)
+    , mIsMainScript(aIsMainScript)
+    , mIsFromCache(false)
   {
     MOZ_ASSERT(aManager);
     AssertIsOnMainThread();
@@ -180,8 +181,6 @@ private:
   RefPtr<CompareCache> mCC;
   RefPtr<ServiceWorkerRegistrationInfo> mRegistration;
 
-  bool mIsMainScript;
-
   nsCOMPtr<nsIChannel> mChannel;
   nsString mBuffer;
   nsString mURL;
@@ -202,6 +201,9 @@ private:
 
   nsresult mNetworkResult;
   nsresult mCacheResult;
+
+  const bool mIsMainScript;
+  bool mIsFromCache;
 };
 
 NS_IMPL_ISUPPORTS(CompareNetwork, nsIStreamLoaderObserver,
@@ -863,6 +865,12 @@ CompareNetwork::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
   }
 
   mInternalHeaders->FillResponseHeaders(mChannel);
+
+  nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(mChannel));
+  if (cacheChannel) {
+    cacheChannel->IsFromCache(&mIsFromCache);
+  }
+
   return NS_OK;
 }
 
@@ -959,15 +967,9 @@ CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext
       NS_LITERAL_CSTRING("Service-Worker-Allowed"),
       mMaxScope);
 
-  bool isFromCache = false;
-  nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(httpChannel));
-  if (cacheChannel) {
-    cacheChannel->IsFromCache(&isFromCache);
-  }
-
   // [9.2 Update]4.13, If response's cache state is not "local",
   // set registration's last update check time to the current time
-  if (!isFromCache) {
+  if (!mIsFromCache) {
     mRegistration->RefreshLastUpdateCheckTime();
   }
 

commit 5aebe3f6b13b
Author: Ben Kelly <ben@wanderview.com>
Date:   Tue Oct 24 09:24:53 2017 -0400

    Bug 1410634 - Part 2: Verify ServiceWorkerInfo.lastUpdateTime is not changed when reading from http cache. r=tt, a=ritu
    
    --HG--
    extra : source : 1abb70007b4c50a588b6a344879fd9efc3ef9ca5
---
 .../test/serviceworkers/serviceworkerinfo_iframe.html        |  3 ++-
 .../test_devtools_track_serviceworker_time.html              | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git dom/workers/test/serviceworkers/serviceworkerinfo_iframe.html dom/workers/test/serviceworkers/serviceworkerinfo_iframe.html
index a0a2de76030e..16a175836981 100644
--- dom/workers/test/serviceworkers/serviceworkerinfo_iframe.html
+++ dom/workers/test/serviceworkers/serviceworkerinfo_iframe.html
@@ -7,7 +7,8 @@
         if (event.data !== "register") {
           return;
         }
-        var promise = navigator.serviceWorker.register("worker.js");
+        var promise = navigator.serviceWorker.register("worker.js",
+                                                       { updateViaCache: 'all' });
         window.onmessage = function (event) {
           if (event.data !== "unregister") {
             return;
diff --git dom/workers/test/serviceworkers/test_devtools_track_serviceworker_time.html dom/workers/test/serviceworkers/test_devtools_track_serviceworker_time.html
index 4b58d659f565..6b95d6b34fe1 100644
--- dom/workers/test/serviceworkers/test_devtools_track_serviceworker_time.html
+++ dom/workers/test/serviceworkers/test_devtools_track_serviceworker_time.html
@@ -53,6 +53,8 @@ let expectedResults = [
     state: State.ACTIVATED, installedTimeRecorded: true,
     activatedTimeRecorded: true, redundantTimeRecorded: false
   },
+
+  // On unregister
   {
     state: State.REDUNDANT, installedTimeRecorded: true,
     activatedTimeRecorded: true, redundantTimeRecorded: true
@@ -170,6 +172,15 @@ function testServiceWorkerInfo() {
   return promise;
 }
 
+async function testHttpCacheUpdateTime() {
+  let iframe = document.querySelector("iframe");
+  let reg = await iframe.contentWindow.navigator.serviceWorker.getRegistration();
+  let lastUpdateTime = registrationInfo.lastUpdateTime;
+  await reg.update();
+  is(lastUpdateTime, registrationInfo.lastUpdateTime,
+     "The update time should not change when SW script is read from http cache.");
+}
+
 function unregister() {
   info("Unregister the ServiceWorker");
 
@@ -196,6 +207,7 @@ function runTest() {
   return Promise.resolve()
     .then(register)
     .then(testServiceWorkerInfo)
+    .then(testHttpCacheUpdateTime)
     .then(unregister)
     .catch(aError => ok(false, "Some test failed with error " + aError))
     .then(cleanAll)