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

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

Issue 1905873002: Add content_browsertests for testing cache control flags (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reload.html wasn't there Created 4 years, 7 months 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <memory>
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/shell/browser/shell.h"
13 #include "net/test/embedded_test_server/embedded_test_server.h"
14 #include "net/test/embedded_test_server/http_request.h"
15 #include "net/test/embedded_test_server/http_response.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h"
18
19 namespace content {
20
21 namespace {
22
23 using net::test_server::HttpRequest;
24 using net::test_server::HttpResponse;
25
26 const char kReloadTestPath[] = "/loader/reload.html";
27 const char kReloadImagePath[] = "/loader/empty16x16.png";
28
29 const char kNoCacheControl[] = "";
30 const char kMaxAgeCacheControl[] = "max-age=0";
31 const char kNoCacheCacheControl[] = "no-cache";
32
33 struct RequestLog {
34 std::string relative_url;
35 std::string cache_control;
36 };
37
38 class ReloadCacheControlBrowserTest : public ContentBrowserTest {
39 protected:
40 ReloadCacheControlBrowserTest() = default;
41 ~ReloadCacheControlBrowserTest() override {}
kinuko 2016/05/12 08:45:05 nit: any reason we don't make this = default for t
Takashi Toyoshima 2016/05/13 05:27:13 Done.
42
43 void SetUp() override {
kinuko 2016/05/12 08:45:05 Could we do these in SetUpOnMainThread so that we
Takashi Toyoshima 2016/05/13 05:27:13 Sounds better. Thanks.
44 // ContentBrowserTest creates embedded_test_server instance with
45 // a registered HandleFileRequest for "content/test/data".
46 // Because the handler is registered as the first handler, MonitorHandler
47 // is needed to capture all requests.
48 embedded_test_server()->RegisterRequestMonitor(base::Bind(
49 &ReloadCacheControlBrowserTest::MonitorRequestHandler, this));
50
51 embedded_test_server()->Start();
kinuko 2016/05/12 08:45:05 ASSERT_TRUE(...)
Takashi Toyoshima 2016/05/13 05:27:13 Thanks. Probably it's better to add WARN_UNUSED_RE
52
53 ContentBrowserTest::SetUp();
54 }
55
56 protected:
57 std::vector<RequestLog> request_log_;
58
59 private:
60 void MonitorRequestHandler(const HttpRequest& request) {
61 RequestLog log;
62 log.relative_url = request.relative_url;
63 auto cache_control = request.headers.find("Cache-Control");
64 log.cache_control = cache_control == request.headers.end()
65 ? kNoCacheControl
66 : cache_control->second;
67 request_log_.push_back(log);
68 }
69
70 DISALLOW_COPY_AND_ASSIGN(ReloadCacheControlBrowserTest);
71 };
72
73 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, NormalReload) {
74 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
75
76 EXPECT_TRUE(NavigateToURL(shell(), url));
77 ReloadBlockUntilNavigationsComplete(shell(), 1);
78
79 ASSERT_EQ(4UL, request_log_.size());
80 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
81 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
82 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
83 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
84
85 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
86 EXPECT_EQ(kMaxAgeCacheControl, request_log_[2].cache_control);
87 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
88 EXPECT_EQ(kMaxAgeCacheControl, request_log_[3].cache_control);
89 }
90
91 IN_PROC_BROWSER_TEST_F(ReloadCacheControlBrowserTest, BypassingReload) {
92 GURL url(embedded_test_server()->GetURL(kReloadTestPath));
93
94 EXPECT_TRUE(NavigateToURL(shell(), url));
95 ReloadBypassingCacheBlockUntilNavigationsComplete(shell(), 1);
96
97 ASSERT_EQ(4UL, request_log_.size());
98 EXPECT_EQ(kReloadTestPath, request_log_[0].relative_url);
99 EXPECT_EQ(kNoCacheControl, request_log_[0].cache_control);
100 EXPECT_EQ(kReloadImagePath, request_log_[1].relative_url);
101 EXPECT_EQ(kNoCacheControl, request_log_[1].cache_control);
102
103 EXPECT_EQ(kReloadTestPath, request_log_[2].relative_url);
104 EXPECT_EQ(kNoCacheCacheControl, request_log_[2].cache_control);
105 EXPECT_EQ(kReloadImagePath, request_log_[3].relative_url);
106 EXPECT_EQ(kNoCacheCacheControl, request_log_[3].cache_control);
107 }
108
109 } // namespace
110
111 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/content_tests.gypi » ('j') | net/test/embedded_test_server/embedded_test_server.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698