OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <stdint.h> |
| 6 |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" |
6 #include "base/path_service.h" | 9 #include "base/path_service.h" |
7 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
8 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
9 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
10 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
11 #include "content/public/common/manifest.h" | 14 #include "content/public/common/manifest.h" |
12 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
13 #include "content/public/test/content_browser_test.h" | 16 #include "content/public/test/content_browser_test.h" |
14 #include "content/public/test/content_browser_test_utils.h" | 17 #include "content/public/test/content_browser_test_utils.h" |
15 #include "content/public/test/test_navigation_observer.h" | 18 #include "content/public/test/test_navigation_observer.h" |
16 #include "content/shell/browser/shell.h" | 19 #include "content/shell/browser/shell.h" |
17 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
18 #include "net/test/embedded_test_server/http_request.h" | 21 #include "net/test/embedded_test_server/http_request.h" |
19 #include "net/test/embedded_test_server/http_response.h" | 22 #include "net/test/embedded_test_server/http_response.h" |
20 | 23 |
21 | 24 |
22 namespace content { | 25 namespace content { |
23 | 26 |
24 class ManifestBrowserTest; | 27 class ManifestBrowserTest; |
25 | 28 |
26 // Mock of a WebContentsDelegate that catches messages sent to the console. | 29 // Mock of a WebContentsDelegate that catches messages sent to the console. |
27 class MockWebContentsDelegate : public WebContentsDelegate { | 30 class MockWebContentsDelegate : public WebContentsDelegate { |
28 public: | 31 public: |
29 MockWebContentsDelegate(WebContents* web_contents, ManifestBrowserTest* test) | 32 MockWebContentsDelegate(WebContents* web_contents, ManifestBrowserTest* test) |
30 : web_contents_(web_contents), | 33 : web_contents_(web_contents), |
31 test_(test) { | 34 test_(test) { |
32 } | 35 } |
33 | 36 |
34 bool AddMessageToConsole(WebContents* source, | 37 bool AddMessageToConsole(WebContents* source, |
35 int32 level, | 38 int32_t level, |
36 const base::string16& message, | 39 const base::string16& message, |
37 int32 line_no, | 40 int32_t line_no, |
38 const base::string16& source_id) override; | 41 const base::string16& source_id) override; |
39 | 42 |
40 private: | 43 private: |
41 WebContents* web_contents_; | 44 WebContents* web_contents_; |
42 ManifestBrowserTest* test_; | 45 ManifestBrowserTest* test_; |
43 }; | 46 }; |
44 | 47 |
45 class ManifestBrowserTest : public ContentBrowserTest { | 48 class ManifestBrowserTest : public ContentBrowserTest { |
46 protected: | 49 protected: |
47 friend MockWebContentsDelegate; | 50 friend MockWebContentsDelegate; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 int console_error_count_; | 122 int console_error_count_; |
120 bool has_manifest_; | 123 bool has_manifest_; |
121 | 124 |
122 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); | 125 DISALLOW_COPY_AND_ASSIGN(ManifestBrowserTest); |
123 }; | 126 }; |
124 | 127 |
125 // The implementation of AddMessageToConsole isn't inlined because it needs | 128 // The implementation of AddMessageToConsole isn't inlined because it needs |
126 // to know about |test_|. | 129 // to know about |test_|. |
127 bool MockWebContentsDelegate::AddMessageToConsole( | 130 bool MockWebContentsDelegate::AddMessageToConsole( |
128 WebContents* source, | 131 WebContents* source, |
129 int32 level, | 132 int32_t level, |
130 const base::string16& message, | 133 const base::string16& message, |
131 int32 line_no, | 134 int32_t line_no, |
132 const base::string16& source_id) { | 135 const base::string16& source_id) { |
133 DCHECK(source == web_contents_); | 136 DCHECK(source == web_contents_); |
134 | 137 |
135 if (level == logging::LOG_ERROR) | 138 if (level == logging::LOG_ERROR) |
136 test_->OnReceivedConsoleError(); | 139 test_->OnReceivedConsoleError(); |
137 return false; | 140 return false; |
138 } | 141 } |
139 | 142 |
140 // If a page has no manifest, requesting a manifest should return the empty | 143 // If a page has no manifest, requesting a manifest should return the empty |
141 // manifest. | 144 // manifest. |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 HasManifestAndWait(); | 599 HasManifestAndWait(); |
597 EXPECT_TRUE(has_manifest()); | 600 EXPECT_TRUE(has_manifest()); |
598 EXPECT_EQ(0u, console_error_count()); | 601 EXPECT_EQ(0u, console_error_count()); |
599 | 602 |
600 // The custom embedded test server will fill set the name to 'no cookies' if | 603 // The custom embedded test server will fill set the name to 'no cookies' if |
601 // it did not find cookies. | 604 // it did not find cookies. |
602 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies")); | 605 EXPECT_TRUE(base::EqualsASCII(manifest().name.string(), "no cookies")); |
603 } | 606 } |
604 | 607 |
605 } // namespace content | 608 } // namespace content |
OLD | NEW |