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

Side by Side Diff: content/browser/manifest/manifest_browsertest.cc

Issue 537053002: Implement ManifestManager to handle manifest in content/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_fetcher
Patch Set: with tests Created 6 years, 3 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 2014 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 "base/command_line.h"
6 #include "content/public/browser/web_contents.h"
7 #include "content/public/common/content_switches.h"
8 #include "content/public/common/manifest.h"
9 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/public/test/test_navigation_observer.h"
13 #include "content/shell/browser/shell.h"
14 #include "net/test/embedded_test_server/embedded_test_server.h"
15
16 namespace content {
17
18 class ManifestBrowserTest : public ContentBrowserTest {
19 public:
20 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
21 command_line->AppendSwitch(
22 switches::kEnableExperimentalWebPlatformFeatures);
23 }
24
25 protected:
26 void GetManifestAndWait() {
27 shell()->web_contents()->GetManifest(
28 base::Bind(&ManifestBrowserTest::OnGetManifest,
29 base::Unretained(this)));
30
31 message_loop_runner_ = new MessageLoopRunner();
32 message_loop_runner_->Run();
33 }
34
35 void OnGetManifest(const Manifest& manifest) {
36 manifest_ = manifest;
37 message_loop_runner_->Quit();
38 }
39
40 const Manifest& manifest() const {
41 return manifest_;
42 }
43
44 private:
45 scoped_refptr<MessageLoopRunner> message_loop_runner_;
46 Manifest manifest_;
47 };
48
49 // If a page has no manifest, requesting a manifest should return the empty
50 // manifest.
51 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoManifest) {
52 GURL test_url = GetTestUrl("manifest", "no-manifest.html");
53
54 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
55 shell()->LoadURL(test_url);
56 navigation_observer.Wait();
57
58 GetManifestAndWait();
59 EXPECT_TRUE(manifest().IsEmpty());
60 }
61
62 // If a page manifest points to a 404 URL, requesting the manifest should return
63 // the empty manifest.
64 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, 404Manifest) {
65 GURL test_url = GetTestUrl("manifest", "404-manifest.html");
66
67 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
68 shell()->LoadURL(test_url);
69 navigation_observer.Wait();
70
71 GetManifestAndWait();
72 EXPECT_TRUE(manifest().IsEmpty());
73 }
74
75 // If a page has an empty manifest, requesting the manifest should return the
76 // empty manifest.
77 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, EmptyManifest) {
78 GURL test_url = GetTestUrl("manifest", "empty-manifest.html");
79
80 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
81 shell()->LoadURL(test_url);
82 navigation_observer.Wait();
83
84 GetManifestAndWait();
85 EXPECT_TRUE(manifest().IsEmpty());
86 }
87
88 // If a page's manifest can't be parsed correctly, requesting the manifest
89 // should return an empty manifest.
90 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParseErrorManifest) {
91 GURL test_url = GetTestUrl("manifest", "parse-error-manifest.html");
92
93 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
94 shell()->LoadURL(test_url);
95 navigation_observer.Wait();
96
97 GetManifestAndWait();
98 EXPECT_TRUE(manifest().IsEmpty());
99 }
100
101 // If a page has a manifest that can be fetched and parsed, requesting the
102 // manifest should return a properly filed manifest.
103 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DummyManifest) {
104 GURL test_url = GetTestUrl("manifest", "dummy-manifest.html");
105
106 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
107 shell()->LoadURL(test_url);
108 navigation_observer.Wait();
109
110 GetManifestAndWait();
111 EXPECT_FALSE(manifest().IsEmpty());
112 }
113
114 // If a page changes manifest during its runtime, requesting the manifest should
115 // return the current manifest.
116 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DynamicManifest) {
117 GURL test_url = GetTestUrl("manifest", "dynamic-manifest.html");
118
119 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
120 shell()->LoadURL(test_url);
121 navigation_observer.Wait();
122
123 {
124 GetManifestAndWait();
125 EXPECT_TRUE(manifest().IsEmpty());
126 }
127
128 {
129 std::string manifest_url =
130 GetTestUrl("manifest", "dummy-manifest.json").spec();
131 ASSERT_TRUE(content::ExecuteScript(
132 shell()->web_contents(), "setManifestTo('" + manifest_url + "')"));
133
134 GetManifestAndWait();
135 EXPECT_FALSE(manifest().IsEmpty());
136 }
137
138 {
139 std::string manifest_url =
140 GetTestUrl("manifest", "empty-manifest.json").spec();
141 ASSERT_TRUE(content::ExecuteScript(
142 shell()->web_contents(), "setManifestTo('" + manifest_url + "')"));
143
144 GetManifestAndWait();
145 EXPECT_TRUE(manifest().IsEmpty());
146 }
147 }
148
149 // If a page's manifest lives in a different origin, it should follow the CORS
150 // rules and requesting the manifest should return an empty manifest (unless the
151 // response contains CORS headers).
152 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) {
153 scoped_ptr<net::test_server::EmbeddedTestServer> cors_embedded_test_server(
154 new net::test_server::EmbeddedTestServer);
155
156 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
157 ASSERT_TRUE(cors_embedded_test_server->InitializeAndWaitUntilReady());
158 ASSERT_NE(embedded_test_server()->port(), cors_embedded_test_server->port());
159
160 GURL test_url =
161 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
162
163 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
164 shell()->LoadURL(test_url);
165 navigation_observer.Wait();
166
167 std::string manifest_url =
168 cors_embedded_test_server->GetURL("/manifest/dummy-manifest.json").spec();
169 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(),
170 "setManifestTo('" + manifest_url + "')"));
171
172 GetManifestAndWait();
173 EXPECT_TRUE(manifest().IsEmpty());
174 }
175
176 // If a page's manifest is in an unsecure origin while the page is in a secure
177 // origin, requesting the manifest should return the empty manifest.
178 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) {
179 scoped_ptr<net::SpawnedTestServer> https_server(new net::SpawnedTestServer(
180 net::SpawnedTestServer::TYPE_HTTPS,
181 net::BaseTestServer::SSLOptions(net::BaseTestServer::SSLOptions::CERT_OK),
182 base::FilePath(FILE_PATH_LITERAL("content/test/data"))));
183
184 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
185 ASSERT_TRUE(https_server->Start());
186
187 GURL test_url =
188 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html");
189
190 TestNavigationObserver navigation_observer(shell()->web_contents(), 1);
191 shell()->LoadURL(test_url);
192 navigation_observer.Wait();
193
194 std::string manifest_url =
195 https_server->GetURL("/manifest/dummy-manifest.json").spec();
196 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(),
197 "setManifestTo('" + manifest_url + "')"));
198
199 GetManifestAndWait();
200 EXPECT_TRUE(manifest().IsEmpty());
201 }
202
203 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698