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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 21955003: Cleanup: Use content::kAboutBlankURL instead of the raw string in contents/. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix build Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "content/browser/renderer_host/render_view_host_impl.h" 7 #include "content/browser/renderer_host/render_view_host_impl.h"
8 #include "content/browser/renderer_host/test_render_view_host.h" 8 #include "content/browser/renderer_host/test_render_view_host.h"
9 #include "content/browser/site_instance_impl.h" 9 #include "content/browser/site_instance_impl.h"
10 #include "content/browser/web_contents/frame_tree_node.h" 10 #include "content/browser/web_contents/frame_tree_node.h"
11 #include "content/browser/web_contents/interstitial_page_impl.h" 11 #include "content/browser/web_contents/interstitial_page_impl.h"
12 #include "content/browser/web_contents/navigation_entry_impl.h" 12 #include "content/browser/web_contents/navigation_entry_impl.h"
13 #include "content/browser/webui/web_ui_controller_factory_registry.h" 13 #include "content/browser/webui/web_ui_controller_factory_registry.h"
14 #include "content/common/view_messages.h" 14 #include "content/common/view_messages.h"
15 #include "content/public/browser/global_request_id.h" 15 #include "content/public/browser/global_request_id.h"
16 #include "content/public/browser/interstitial_page_delegate.h" 16 #include "content/public/browser/interstitial_page_delegate.h"
17 #include "content/public/browser/navigation_details.h" 17 #include "content/public/browser/navigation_details.h"
18 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/render_widget_host_view.h" 20 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/browser/web_contents_observer.h" 21 #include "content/public/browser/web_contents_observer.h"
23 #include "content/public/browser/web_ui_controller.h" 22 #include "content/public/browser/web_ui_controller.h"
24 #include "content/public/common/bindings_policy.h" 23 #include "content/public/common/bindings_policy.h"
25 #include "content/public/common/content_constants.h" 24 #include "content/public/common/content_constants.h"
26 #include "content/public/common/url_constants.h" 25 #include "content/public/common/url_constants.h"
27 #include "content/public/test/mock_render_process_host.h" 26 #include "content/public/test/mock_render_process_host.h"
28 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
29 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
30 #include "content/test/test_content_browser_client.h" 29 #include "content/test/test_content_browser_client.h"
31 #include "content/test/test_content_client.h" 30 #include "content/test/test_content_client.h"
32 #include "content/test/test_web_contents.h" 31 #include "content/test/test_web_contents.h"
33 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
34 33
35 namespace content { 34 namespace content {
36 namespace { 35 namespace {
37 36
38 const char kTestWebUIUrl[] = "chrome://blah"; 37 const char kTestWebUIUrl[] = "chrome://blah";
39 38
40 class WebContentsImplTestWebUIControllerFactory 39 class WebContentsImplTestWebUIControllerFactory
41 : public WebUIControllerFactory { 40 : public WebUIControllerFactory {
42 public: 41 public:
43 virtual WebUIController* CreateWebUIControllerForURL( 42 virtual WebUIController* CreateWebUIControllerForURL(
44 WebUI* web_ui, const GURL& url) const OVERRIDE { 43 WebUI* web_ui, const GURL& url) const OVERRIDE {
45 if (!UseWebUI(url)) 44 if (!UseWebUI(url))
46 return NULL; 45 return NULL;
47 46 return new WebUIController(web_ui);
48 return new WebUIController(web_ui);
49 } 47 }
50 48
51 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, 49 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context,
52 const GURL& url) const OVERRIDE { 50 const GURL& url) const OVERRIDE {
53 return WebUI::kNoWebUI; 51 return WebUI::kNoWebUI;
54 } 52 }
55 53
56 virtual bool UseWebUIForURL(BrowserContext* browser_context, 54 virtual bool UseWebUIForURL(BrowserContext* browser_context,
57 const GURL& url) const OVERRIDE { 55 const GURL& url) const OVERRIDE {
58 return UseWebUI(url); 56 return UseWebUI(url);
59 } 57 }
60 58
61 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, 59 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context,
62 const GURL& url) const OVERRIDE { 60 const GURL& url) const OVERRIDE {
63 return UseWebUI(url); 61 return UseWebUI(url);
64 } 62 }
65 63
66 private: 64 private:
67 bool UseWebUI(const GURL& url) const { 65 bool UseWebUI(const GURL& url) const {
68 return url == GURL(kTestWebUIUrl); 66 return url == GURL(kTestWebUIUrl);
69 } 67 }
70 }; 68 };
71 69
72 class TestInterstitialPage; 70 class TestInterstitialPage;
73 71
74 class TestInterstitialPageDelegate : public InterstitialPageDelegate { 72 class TestInterstitialPageDelegate : public InterstitialPageDelegate {
75 public: 73 public:
76 TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page) 74 explicit TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page)
77 : interstitial_page_(interstitial_page) {} 75 : interstitial_page_(interstitial_page) {}
78 virtual void CommandReceived(const std::string& command) OVERRIDE; 76 virtual void CommandReceived(const std::string& command) OVERRIDE;
79 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } 77 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); }
80 virtual void OnDontProceed() OVERRIDE; 78 virtual void OnDontProceed() OVERRIDE;
81 virtual void OnProceed() OVERRIDE; 79 virtual void OnProceed() OVERRIDE;
82 private: 80 private:
83 TestInterstitialPage* interstitial_page_; 81 TestInterstitialPage* interstitial_page_;
84 }; 82 };
85 83
86 class TestInterstitialPage : public InterstitialPageImpl { 84 class TestInterstitialPage : public InterstitialPageImpl {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); 262 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_);
265 RenderViewHostImplTestHarness::TearDown(); 263 RenderViewHostImplTestHarness::TearDown();
266 } 264 }
267 265
268 private: 266 private:
269 WebContentsImplTestWebUIControllerFactory factory_; 267 WebContentsImplTestWebUIControllerFactory factory_;
270 }; 268 };
271 269
272 class TestWebContentsObserver : public WebContentsObserver { 270 class TestWebContentsObserver : public WebContentsObserver {
273 public: 271 public:
274 TestWebContentsObserver(WebContents* contents) 272 explicit TestWebContentsObserver(WebContents* contents)
275 : WebContentsObserver(contents) { 273 : WebContentsObserver(contents) {
276 } 274 }
277 virtual ~TestWebContentsObserver() {} 275 virtual ~TestWebContentsObserver() {}
278 276
279 virtual void DidFinishLoad(int64 frame_id, 277 virtual void DidFinishLoad(int64 frame_id,
280 const GURL& validated_url, 278 const GURL& validated_url,
281 bool is_main_frame, 279 bool is_main_frame,
282 RenderViewHost* render_view_host) OVERRIDE { 280 RenderViewHost* render_view_host) OVERRIDE {
283 last_url_ = validated_url; 281 last_url_ = validated_url;
284 } 282 }
(...skipping 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after
2103 EXPECT_FALSE(other_controller.CanPruneAllButVisible()); 2101 EXPECT_FALSE(other_controller.CanPruneAllButVisible());
2104 } 2102 }
2105 2103
2106 // Regression test for http://crbug.com/168611 - the URLs passed by the 2104 // Regression test for http://crbug.com/168611 - the URLs passed by the
2107 // DidFinishLoad and DidFailLoadWithError IPCs should get filtered. 2105 // DidFinishLoad and DidFailLoadWithError IPCs should get filtered.
2108 TEST_F(WebContentsImplTest, FilterURLs) { 2106 TEST_F(WebContentsImplTest, FilterURLs) {
2109 TestWebContentsObserver observer(contents()); 2107 TestWebContentsObserver observer(contents());
2110 2108
2111 // A navigation to about:whatever should always look like a navigation to 2109 // A navigation to about:whatever should always look like a navigation to
2112 // about:blank 2110 // about:blank
2113 GURL url_normalized("about:blank"); 2111 GURL url_normalized(kAboutBlankURL);
2114 GURL url_from_ipc("about:whatever"); 2112 GURL url_from_ipc("about:whatever");
2115 2113
2116 // We navigate the test WebContents to about:blank, since NavigateAndCommit 2114 // We navigate the test WebContents to about:blank, since NavigateAndCommit
2117 // will use the given URL to create the NavigationEntry as well, and that 2115 // will use the given URL to create the NavigationEntry as well, and that
2118 // entry should contain the filtered URL. 2116 // entry should contain the filtered URL.
2119 contents()->NavigateAndCommit(url_normalized); 2117 contents()->NavigateAndCommit(url_normalized);
2120 2118
2121 // Check that an IPC with about:whatever is correctly normalized. 2119 // Check that an IPC with about:whatever is correctly normalized.
2122 contents()->TestDidFinishLoad(1, url_from_ipc, true); 2120 contents()->TestDidFinishLoad(1, url_from_ipc, true);
2123 2121
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2218 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count()); 2216 EXPECT_EQ(0UL, deep_tree->child_at(0)->child_at(0)->child_count());
2219 2217
2220 contents()->OnFrameDetached(16, 265); 2218 contents()->OnFrameDetached(16, 265);
2221 EXPECT_EQ(4UL, root->child_at(2)->child_count()); 2219 EXPECT_EQ(4UL, root->child_at(2)->child_count());
2222 2220
2223 contents()->OnFrameDetached(5, 15); 2221 contents()->OnFrameDetached(5, 15);
2224 EXPECT_EQ(2UL, root->child_count()); 2222 EXPECT_EQ(2UL, root->child_count());
2225 } 2223 }
2226 2224
2227 } // namespace content 2225 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/navigation_controller_impl_unittest.cc ('k') | content/renderer/cpp_bound_class_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698