Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: content/browser/loader/async_revalidation_manager_browsertest.cc

Issue 2571473002: Fix cases where RunLoop is created without a MessageLoop. (Closed)
Patch Set: Fix chromeos tests. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 30 matching lines...) Expand all
41 class AsyncRevalidationManagerBrowserTest : public ContentBrowserTest { 41 class AsyncRevalidationManagerBrowserTest : public ContentBrowserTest {
42 protected: 42 protected:
43 AsyncRevalidationManagerBrowserTest() {} 43 AsyncRevalidationManagerBrowserTest() {}
44 ~AsyncRevalidationManagerBrowserTest() override {} 44 ~AsyncRevalidationManagerBrowserTest() override {}
45 45
46 void SetUp() override { 46 void SetUp() override {
47 scoped_feature_list_.InitAndEnableFeature(features::kStaleWhileRevalidate); 47 scoped_feature_list_.InitAndEnableFeature(features::kStaleWhileRevalidate);
48 ContentBrowserTest::SetUp(); 48 ContentBrowserTest::SetUp();
49 } 49 }
50 50
51 base::RunLoop* run_loop() { return &run_loop_; } 51 void SetUpOnMainThread() override {
52 ContentBrowserTest::SetUpOnMainThread();
53 run_loop_.reset(new base::RunLoop);
54 }
55
56 base::RunLoop* run_loop() {
57 DCHECK(run_loop_);
58 return run_loop_.get();
59 }
60
52 int requests_counted() const { return requests_counted_; } 61 int requests_counted() const { return requests_counted_; }
53 62
54 // This method lacks diagnostics for the failure case because TitleWatcher 63 // This method lacks diagnostics for the failure case because TitleWatcher
55 // will just wait until the test times out if |expected_title| does not 64 // will just wait until the test times out if |expected_title| does not
56 // appear. 65 // appear.
57 bool TitleBecomes(const GURL& url, const std::string& expected_title) { 66 bool TitleBecomes(const GURL& url, const std::string& expected_title) {
58 base::string16 expected_title16(base::ASCIIToUTF16(expected_title)); 67 base::string16 expected_title16(base::ASCIIToUTF16(expected_title));
59 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); 68 TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
60 NavigateToURL(shell(), url); 69 NavigateToURL(shell(), url);
61 return title_watcher.WaitAndGetTitle() == expected_title16; 70 return title_watcher.WaitAndGetTitle() == expected_title16;
(...skipping 23 matching lines...) Expand all
85 94
86 std::unique_ptr<BasicHttpResponse> http_response( 95 std::unique_ptr<BasicHttpResponse> http_response(
87 StaleWhileRevalidateHeaders()); 96 StaleWhileRevalidateHeaders());
88 http_response->set_content( 97 http_response->set_content(
89 base::StringPrintf("<title>Version %d</title>", version)); 98 base::StringPrintf("<title>Version %d</title>", version));
90 99
91 // The second time this handler is run is the async revalidation. Tests can 100 // The second time this handler is run is the async revalidation. Tests can
92 // use this for synchronisation. 101 // use this for synchronisation.
93 if (version == 2) { 102 if (version == 2) {
94 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 103 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
95 run_loop_.QuitClosure()); 104 run_loop()->QuitClosure());
96 } 105 }
97 return std::move(http_response); 106 return std::move(http_response);
98 } 107 }
99 108
100 // A request handler which increases a cookie value on every request. 109 // A request handler which increases a cookie value on every request.
101 std::unique_ptr<HttpResponse> CookieRequestHandler( 110 std::unique_ptr<HttpResponse> CookieRequestHandler(
102 const HttpRequest& request) { 111 const HttpRequest& request) {
103 static const char kHtml[] = 112 static const char kHtml[] =
104 "<script>\n" 113 "<script>\n"
105 "var intervalId;\n" 114 "var intervalId;\n"
(...skipping 29 matching lines...) Expand all
135 http_response->AddCustomHeader("Cache-Control", 144 http_response->AddCustomHeader("Cache-Control",
136 "max-age=0, stale-while-revalidate=86400"); 145 "max-age=0, stale-while-revalidate=86400");
137 // A validator is needed for revalidations, and hence 146 // A validator is needed for revalidations, and hence
138 // stale-while-revalidate, to work. 147 // stale-while-revalidate, to work.
139 std::string etag = base::StringPrintf( 148 std::string etag = base::StringPrintf(
140 "\"AsyncRevalidationManagerBrowserTest%d\"", requests_counted_); 149 "\"AsyncRevalidationManagerBrowserTest%d\"", requests_counted_);
141 http_response->AddCustomHeader("ETag", etag); 150 http_response->AddCustomHeader("ETag", etag);
142 return http_response; 151 return http_response;
143 } 152 }
144 153
145 base::RunLoop run_loop_; 154 std::unique_ptr<base::RunLoop> run_loop_;
146 int requests_counted_ = 0; 155 int requests_counted_ = 0;
147 base::test::ScopedFeatureList scoped_feature_list_; 156 base::test::ScopedFeatureList scoped_feature_list_;
148 157
149 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationManagerBrowserTest); 158 DISALLOW_COPY_AND_ASSIGN(AsyncRevalidationManagerBrowserTest);
150 }; 159 };
151 160
152 // Verify that the "Cache-Control: stale-while-revalidate" directive correctly 161 // Verify that the "Cache-Control: stale-while-revalidate" directive correctly
153 // triggers an async revalidation. 162 // triggers an async revalidation.
154 IN_PROC_BROWSER_TEST_F(AsyncRevalidationManagerBrowserTest, 163 IN_PROC_BROWSER_TEST_F(AsyncRevalidationManagerBrowserTest,
155 StaleWhileRevalidateIsApplied) { 164 StaleWhileRevalidateIsApplied) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 NavigateToURL(shell(), GURL("about:blank")); 241 NavigateToURL(shell(), GURL("about:blank"));
233 242
234 // The page will load from the cache, then when the async revalidation 243 // The page will load from the cache, then when the async revalidation
235 // completes the cookie will update. 244 // completes the cookie will update.
236 EXPECT_TRUE(TitleBecomes(url, "PASS")); 245 EXPECT_TRUE(TitleBecomes(url, "PASS"));
237 } 246 }
238 247
239 } // namespace 248 } // namespace
240 249
241 } // namespace content 250 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/system/device_disabling_browsertest.cc ('k') | media/base/audio_renderer_mixer_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698