OLD | NEW |
---|---|
(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 protected: | |
20 void GetManifestAndWait() { | |
21 shell()->web_contents()->GetManifest( | |
22 base::Bind(&ManifestBrowserTest::OnGetManifest, | |
23 base::Unretained(this))); | |
24 | |
25 message_loop_runner_ = new MessageLoopRunner(); | |
26 message_loop_runner_->Run(); | |
27 } | |
28 | |
29 void OnGetManifest(const Manifest& manifest) { | |
30 manifest_ = manifest; | |
31 message_loop_runner_->Quit(); | |
32 } | |
33 | |
34 const Manifest& manifest() const { | |
35 return manifest_; | |
36 } | |
37 | |
38 private: | |
39 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
40 Manifest manifest_; | |
41 }; | |
42 | |
43 // If a page has no manifest, requesting a manifest should return the empty | |
44 // manifest. | |
45 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, NoManifest) { | |
46 GURL test_url = GetTestUrl("manifest", "no-manifest.html"); | |
47 | |
48 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | |
49 shell()->LoadURL(test_url); | |
50 navigation_observer.Wait(); | |
51 | |
52 GetManifestAndWait(); | |
53 EXPECT_TRUE(manifest().IsEmpty()); | |
54 } | |
55 | |
56 // If a page manifest points to a 404 URL, requesting the manifest should return | |
57 // the empty manifest. | |
58 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, 404Manifest) { | |
59 GURL test_url = GetTestUrl("manifest", "404-manifest.html"); | |
60 | |
61 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | |
62 shell()->LoadURL(test_url); | |
63 navigation_observer.Wait(); | |
64 | |
65 GetManifestAndWait(); | |
66 EXPECT_TRUE(manifest().IsEmpty()); | |
67 } | |
68 | |
69 // If a page has an empty manifest, requesting the manifest should return the | |
70 // empty manifest. | |
71 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, EmptyManifest) { | |
72 GURL test_url = GetTestUrl("manifest", "empty-manifest.html"); | |
73 | |
74 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | |
75 shell()->LoadURL(test_url); | |
76 navigation_observer.Wait(); | |
77 | |
78 GetManifestAndWait(); | |
79 EXPECT_TRUE(manifest().IsEmpty()); | |
80 } | |
81 | |
82 // If a page's manifest can't be parsed correctly, requesting the manifest | |
83 // should return an empty manifest. | |
84 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, ParseErrorManifest) { | |
85 GURL test_url = GetTestUrl("manifest", "parse-error-manifest.html"); | |
86 | |
87 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | |
88 shell()->LoadURL(test_url); | |
89 navigation_observer.Wait(); | |
90 | |
91 GetManifestAndWait(); | |
92 EXPECT_TRUE(manifest().IsEmpty()); | |
93 } | |
94 | |
95 // If a page has a manifest that can be fetched and parsed, requesting the | |
96 // manifest should return a properly filed manifest. | |
kenneth.christiansen
2014/09/11 09:33:09
filled*
mlamouri (slow - plz ping)
2014/09/11 10:30:32
Done.
| |
97 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DummyManifest) { | |
98 GURL test_url = GetTestUrl("manifest", "dummy-manifest.html"); | |
99 | |
100 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | |
101 shell()->LoadURL(test_url); | |
102 navigation_observer.Wait(); | |
103 | |
104 GetManifestAndWait(); | |
105 EXPECT_FALSE(manifest().IsEmpty()); | |
kenneth.christiansen
2014/09/11 09:33:09
So this test is supposed to fail for now? empty do
mlamouri (slow - plz ping)
2014/09/11 10:30:32
dummy-manifest.json isn't empty. The test checks t
| |
106 } | |
107 | |
108 // If a page changes manifest during its runtime, requesting the manifest should | |
kenneth.christiansen
2014/09/11 09:33:09
s/runtime/life-time/ ?
mlamouri (slow - plz ping)
2014/09/11 10:30:32
Done.
| |
109 // return the current manifest. | |
110 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, DynamicManifest) { | |
111 GURL test_url = GetTestUrl("manifest", "dynamic-manifest.html"); | |
112 | |
113 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | |
114 shell()->LoadURL(test_url); | |
115 navigation_observer.Wait(); | |
116 | |
117 { | |
118 GetManifestAndWait(); | |
119 EXPECT_TRUE(manifest().IsEmpty()); | |
120 } | |
121 | |
122 { | |
123 std::string manifest_url = | |
124 GetTestUrl("manifest", "dummy-manifest.json").spec(); | |
125 ASSERT_TRUE(content::ExecuteScript( | |
126 shell()->web_contents(), "setManifestTo('" + manifest_url + "')")); | |
127 | |
128 GetManifestAndWait(); | |
129 EXPECT_FALSE(manifest().IsEmpty()); | |
130 } | |
131 | |
132 { | |
133 std::string manifest_url = | |
134 GetTestUrl("manifest", "empty-manifest.json").spec(); | |
135 ASSERT_TRUE(content::ExecuteScript( | |
136 shell()->web_contents(), "setManifestTo('" + manifest_url + "')")); | |
137 | |
138 GetManifestAndWait(); | |
139 EXPECT_TRUE(manifest().IsEmpty()); | |
140 } | |
141 } | |
142 | |
143 // If a page's manifest lives in a different origin, it should follow the CORS | |
144 // rules and requesting the manifest should return an empty manifest (unless the | |
145 // response contains CORS headers). | |
146 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, CORSManifest) { | |
147 scoped_ptr<net::test_server::EmbeddedTestServer> cors_embedded_test_server( | |
148 new net::test_server::EmbeddedTestServer); | |
149 | |
150 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
151 ASSERT_TRUE(cors_embedded_test_server->InitializeAndWaitUntilReady()); | |
152 ASSERT_NE(embedded_test_server()->port(), cors_embedded_test_server->port()); | |
153 | |
154 GURL test_url = | |
155 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); | |
156 | |
157 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | |
158 shell()->LoadURL(test_url); | |
159 navigation_observer.Wait(); | |
160 | |
161 std::string manifest_url = | |
162 cors_embedded_test_server->GetURL("/manifest/dummy-manifest.json").spec(); | |
163 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), | |
164 "setManifestTo('" + manifest_url + "')")); | |
165 | |
166 GetManifestAndWait(); | |
167 EXPECT_TRUE(manifest().IsEmpty()); | |
168 } | |
169 | |
170 // If a page's manifest is in an unsecure origin while the page is in a secure | |
171 // origin, requesting the manifest should return the empty manifest. | |
172 IN_PROC_BROWSER_TEST_F(ManifestBrowserTest, MixedContentManifest) { | |
173 scoped_ptr<net::SpawnedTestServer> https_server(new net::SpawnedTestServer( | |
174 net::SpawnedTestServer::TYPE_HTTPS, | |
175 net::BaseTestServer::SSLOptions(net::BaseTestServer::SSLOptions::CERT_OK), | |
176 base::FilePath(FILE_PATH_LITERAL("content/test/data")))); | |
177 | |
178 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
179 ASSERT_TRUE(https_server->Start()); | |
180 | |
181 GURL test_url = | |
182 embedded_test_server()->GetURL("/manifest/dynamic-manifest.html"); | |
183 | |
184 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | |
185 shell()->LoadURL(test_url); | |
186 navigation_observer.Wait(); | |
187 | |
188 std::string manifest_url = | |
189 https_server->GetURL("/manifest/dummy-manifest.json").spec(); | |
190 ASSERT_TRUE(content::ExecuteScript(shell()->web_contents(), | |
191 "setManifestTo('" + manifest_url + "')")); | |
192 | |
193 GetManifestAndWait(); | |
194 EXPECT_TRUE(manifest().IsEmpty()); | |
195 } | |
196 | |
197 } // namespace content | |
OLD | NEW |