OLD | NEW |
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 "content/browser/browser_thread_impl.h" | 5 #include "content/browser/browser_thread_impl.h" |
6 #include "content/browser/browser_url_handler.h" | 6 #include "content/browser/browser_url_handler.h" |
7 #include "content/browser/mock_content_browser_client.h" | 7 #include "content/browser/mock_content_browser_client.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/tab_contents/navigation_controller_impl.h" | 10 #include "content/browser/tab_contents/navigation_controller_impl.h" |
11 #include "content/browser/tab_contents/navigation_entry_impl.h" | 11 #include "content/browser/tab_contents/navigation_entry_impl.h" |
12 #include "content/browser/tab_contents/render_view_host_manager.h" | 12 #include "content/browser/tab_contents/render_view_host_manager.h" |
13 #include "content/browser/tab_contents/test_tab_contents.h" | 13 #include "content/browser/tab_contents/test_tab_contents.h" |
14 #include "content/browser/webui/empty_web_ui_factory.h" | |
15 #include "content/common/test_url_constants.h" | 14 #include "content/common/test_url_constants.h" |
16 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
17 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
19 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
20 #include "content/public/browser/web_ui_controller.h" | 19 #include "content/public/browser/web_ui_controller.h" |
| 20 #include "content/public/browser/web_ui_controller_factory.h" |
21 #include "content/public/common/page_transition_types.h" | 21 #include "content/public/common/page_transition_types.h" |
22 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
23 #include "content/test/test_browser_context.h" | 23 #include "content/test/test_browser_context.h" |
24 #include "content/test/test_notification_tracker.h" | 24 #include "content/test/test_notification_tracker.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "googleurl/src/url_util.h" | 26 #include "googleurl/src/url_util.h" |
27 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
28 | 28 |
| 29 using content::BrowserContext; |
29 using content::BrowserThread; | 30 using content::BrowserThread; |
30 using content::BrowserThreadImpl; | 31 using content::BrowserThreadImpl; |
31 using content::NavigationController; | 32 using content::NavigationController; |
32 using content::NavigationEntry; | 33 using content::NavigationEntry; |
33 using content::NavigationEntryImpl; | 34 using content::NavigationEntryImpl; |
34 using content::SiteInstance; | 35 using content::SiteInstance; |
35 using content::WebContents; | 36 using content::WebContents; |
| 37 using content::WebUI; |
36 using content::WebUIController; | 38 using content::WebUIController; |
37 | 39 |
38 namespace { | 40 namespace { |
39 | 41 |
40 const char kChromeUISchemeButNotWebUIURL[] = "chrome://not-webui"; | 42 const char kChromeUISchemeButNotWebUIURL[] = "chrome://not-webui"; |
41 | 43 |
42 class RenderViewHostManagerTestWebUIFactory | 44 class RenderViewHostManagerTestWebUIControllerFactory |
43 : public content::EmptyWebUIFactory { | 45 : public content::WebUIControllerFactory { |
44 public: | 46 public: |
45 RenderViewHostManagerTestWebUIFactory() | 47 RenderViewHostManagerTestWebUIControllerFactory() |
46 : should_create_webui_(false) { | 48 : should_create_webui_(false) { |
47 } | 49 } |
48 virtual ~RenderViewHostManagerTestWebUIFactory() {} | 50 virtual ~RenderViewHostManagerTestWebUIControllerFactory() {} |
49 | 51 |
50 void set_should_create_webui(bool should_create_webui) { | 52 void set_should_create_webui(bool should_create_webui) { |
51 should_create_webui_ = should_create_webui; | 53 should_create_webui_ = should_create_webui; |
52 } | 54 } |
53 | 55 |
54 // WebUIFactory implementation. | 56 // WebUIFactory implementation. |
55 virtual WebUIController* CreateWebUIForURL(content::WebUI* web_ui, | 57 virtual WebUIController* CreateWebUIControllerForURL( |
56 const GURL& url) const OVERRIDE { | 58 WebUI* web_ui, const GURL& url) const OVERRIDE { |
57 if (!(should_create_webui_ && HasWebUIScheme(url))) | 59 if (!(should_create_webui_ && HasWebUIScheme(url))) |
58 return NULL; | 60 return NULL; |
59 return new WebUIController(web_ui); | 61 return new WebUIController(web_ui); |
60 } | 62 } |
61 | 63 |
62 virtual bool UseWebUIForURL(content::BrowserContext* browser_context, | 64 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
| 65 const GURL& url) const OVERRIDE { |
| 66 return WebUI::kNoWebUI; |
| 67 } |
| 68 |
| 69 virtual bool UseWebUIForURL(BrowserContext* browser_context, |
63 const GURL& url) const OVERRIDE { | 70 const GURL& url) const OVERRIDE { |
64 return HasWebUIScheme(url); | 71 return HasWebUIScheme(url); |
65 } | 72 } |
66 | 73 |
67 virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, | 74 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
68 const GURL& url) const OVERRIDE { | 75 const GURL& url) const OVERRIDE { |
69 return HasWebUIScheme(url); | 76 return HasWebUIScheme(url); |
70 } | 77 } |
71 | 78 |
72 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { | 79 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { |
73 return url.SchemeIs(chrome::kChromeUIScheme) && | 80 return url.SchemeIs(chrome::kChromeUIScheme) && |
74 url.spec() != kChromeUISchemeButNotWebUIURL; | 81 url.spec() != kChromeUISchemeButNotWebUIURL; |
75 } | 82 } |
76 | 83 |
| 84 virtual bool IsURLAcceptableForWebUI(BrowserContext* browser_context, |
| 85 const GURL& url) const OVERRIDE { |
| 86 return false; |
| 87 } |
| 88 |
77 private: | 89 private: |
78 bool should_create_webui_; | 90 bool should_create_webui_; |
79 | 91 |
80 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestWebUIFactory); | 92 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestWebUIControllerFactory); |
81 }; | 93 }; |
82 | 94 |
83 class RenderViewHostManagerTestBrowserClient | 95 class RenderViewHostManagerTestBrowserClient |
84 : public content::MockContentBrowserClient { | 96 : public content::MockContentBrowserClient { |
85 public: | 97 public: |
86 RenderViewHostManagerTestBrowserClient() {} | 98 RenderViewHostManagerTestBrowserClient() {} |
87 virtual ~RenderViewHostManagerTestBrowserClient() {} | 99 virtual ~RenderViewHostManagerTestBrowserClient() {} |
88 | 100 |
89 void set_should_create_webui(bool should_create_webui) { | 101 void set_should_create_webui(bool should_create_webui) { |
90 factory_.set_should_create_webui(should_create_webui); | 102 factory_.set_should_create_webui(should_create_webui); |
91 } | 103 } |
92 | 104 |
93 // content::MockContentBrowserClient implementation. | 105 // content::MockContentBrowserClient implementation. |
94 virtual content::WebUIFactory* GetWebUIFactory() OVERRIDE { | 106 virtual content::WebUIControllerFactory* |
| 107 GetWebUIControllerFactory() OVERRIDE { |
95 return &factory_; | 108 return &factory_; |
96 } | 109 } |
97 | 110 |
98 private: | 111 private: |
99 RenderViewHostManagerTestWebUIFactory factory_; | 112 RenderViewHostManagerTestWebUIControllerFactory factory_; |
100 | 113 |
101 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestBrowserClient); | 114 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestBrowserClient); |
102 }; | 115 }; |
103 | 116 |
104 } // namespace | 117 } // namespace |
105 | 118 |
106 class RenderViewHostManagerTest : public RenderViewHostTestHarness { | 119 class RenderViewHostManagerTest : public RenderViewHostTestHarness { |
107 public: | 120 public: |
108 virtual void SetUp() OVERRIDE { | 121 virtual void SetUp() OVERRIDE { |
109 RenderViewHostTestHarness::SetUp(); | 122 RenderViewHostTestHarness::SetUp(); |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 // current one. | 638 // current one. |
626 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> | 639 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> |
627 pending_render_view_host() == NULL); | 640 pending_render_view_host() == NULL); |
628 EXPECT_EQ(evil_rvh, contents()->GetRenderManagerForTesting()->current_host()); | 641 EXPECT_EQ(evil_rvh, contents()->GetRenderManagerForTesting()->current_host()); |
629 | 642 |
630 // Also we should not have a pending navigation entry. | 643 // Also we should not have a pending navigation entry. |
631 NavigationEntry* entry = contents()->GetController().GetActiveEntry(); | 644 NavigationEntry* entry = contents()->GetController().GetActiveEntry(); |
632 ASSERT_TRUE(entry != NULL); | 645 ASSERT_TRUE(entry != NULL); |
633 EXPECT_EQ(kUrl2, entry->GetURL()); | 646 EXPECT_EQ(kUrl2, entry->GetURL()); |
634 } | 647 } |
OLD | NEW |