| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.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/render_view_host.h" | 8 #include "content/browser/renderer_host/render_view_host.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_view.h" | 9 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 10 #include "content/browser/renderer_host/test_render_view_host.h" | 10 #include "content/browser/renderer_host/test_render_view_host.h" |
| 11 #include "content/browser/site_instance_impl.h" | 11 #include "content/browser/site_instance_impl.h" |
| 12 #include "content/browser/tab_contents/interstitial_page.h" | 12 #include "content/browser/tab_contents/interstitial_page.h" |
| 13 #include "content/browser/tab_contents/navigation_entry_impl.h" | 13 #include "content/browser/tab_contents/navigation_entry_impl.h" |
| 14 #include "content/browser/tab_contents/test_tab_contents.h" | 14 #include "content/browser/tab_contents/test_tab_contents.h" |
| 15 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
| 16 #include "content/public/browser/interstitial_page_delegate.h" |
| 16 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 17 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
| 18 #include "content/public/browser/notification_source.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" |
| 20 #include "content/public/browser/web_ui_controller.h" | 21 #include "content/public/browser/web_ui_controller.h" |
| 21 #include "content/public/browser/web_ui_controller_factory.h" | 22 #include "content/public/browser/web_ui_controller_factory.h" |
| 22 #include "content/public/common/bindings_policy.h" | 23 #include "content/public/common/bindings_policy.h" |
| 23 #include "content/public/common/content_constants.h" | 24 #include "content/public/common/content_constants.h" |
| 24 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
| 25 #include "content/test/test_browser_thread.h" | 26 #include "content/test/test_browser_thread.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 82 |
| 82 virtual content::WebUIControllerFactory* | 83 virtual content::WebUIControllerFactory* |
| 83 GetWebUIControllerFactory() OVERRIDE { | 84 GetWebUIControllerFactory() OVERRIDE { |
| 84 return &factory_; | 85 return &factory_; |
| 85 } | 86 } |
| 86 | 87 |
| 87 private: | 88 private: |
| 88 TabContentsTestWebUIControllerFactory factory_; | 89 TabContentsTestWebUIControllerFactory factory_; |
| 89 }; | 90 }; |
| 90 | 91 |
| 92 class TestInterstitialPage; |
| 93 |
| 94 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { |
| 95 public: |
| 96 TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page) |
| 97 : interstitial_page_(interstitial_page) {} |
| 98 virtual void CommandReceived(const std::string& command) OVERRIDE; |
| 99 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } |
| 100 virtual void OnDontProceed() OVERRIDE; |
| 101 virtual void OnProceed() OVERRIDE; |
| 102 private: |
| 103 TestInterstitialPage* interstitial_page_; |
| 104 }; |
| 105 |
| 91 class TestInterstitialPage : public InterstitialPage { | 106 class TestInterstitialPage : public InterstitialPage { |
| 92 public: | 107 public: |
| 93 enum InterstitialState { | 108 enum InterstitialState { |
| 94 UNDECIDED = 0, // No decision taken yet. | 109 UNDECIDED = 0, // No decision taken yet. |
| 95 OKED, // Proceed was called. | 110 OKED, // Proceed was called. |
| 96 CANCELED // DontProceed was called. | 111 CANCELED // DontProceed was called. |
| 97 }; | 112 }; |
| 98 | 113 |
| 99 class Delegate { | 114 class Delegate { |
| 100 public: | 115 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 112 // are cleared when the test finishes. | 127 // are cleared when the test finishes. |
| 113 // Not doing so will cause stack trashing if your test does not hide the | 128 // Not doing so will cause stack trashing if your test does not hide the |
| 114 // interstitial, as in such a case it will be destroyed in the test TearDown | 129 // interstitial, as in such a case it will be destroyed in the test TearDown |
| 115 // method and will dereference the |deleted| local variable which by then is | 130 // method and will dereference the |deleted| local variable which by then is |
| 116 // out of scope. | 131 // out of scope. |
| 117 TestInterstitialPage(TabContents* tab, | 132 TestInterstitialPage(TabContents* tab, |
| 118 bool new_navigation, | 133 bool new_navigation, |
| 119 const GURL& url, | 134 const GURL& url, |
| 120 InterstitialState* state, | 135 InterstitialState* state, |
| 121 bool* deleted) | 136 bool* deleted) |
| 122 : InterstitialPage(tab, new_navigation, url), | 137 : InterstitialPage( |
| 138 tab, new_navigation, url, |
| 139 new TestInterstitialPageDelegate(this)), |
| 123 state_(state), | 140 state_(state), |
| 124 deleted_(deleted), | 141 deleted_(deleted), |
| 125 command_received_count_(0), | 142 command_received_count_(0), |
| 126 delegate_(NULL) { | 143 delegate_(NULL) { |
| 127 *state_ = UNDECIDED; | 144 *state_ = UNDECIDED; |
| 128 *deleted_ = false; | 145 *deleted_ = false; |
| 129 } | 146 } |
| 130 | 147 |
| 131 virtual ~TestInterstitialPage() { | 148 virtual ~TestInterstitialPage() { |
| 132 if (deleted_) | 149 if (deleted_) |
| 133 *deleted_ = true; | 150 *deleted_ = true; |
| 134 if (delegate_) | 151 if (delegate_) |
| 135 delegate_->TestInterstitialPageDeleted(this); | 152 delegate_->TestInterstitialPageDeleted(this); |
| 136 } | 153 } |
| 137 | 154 |
| 138 virtual void DontProceed() { | 155 void OnDontProceed() { |
| 139 if (state_) | 156 if (state_) |
| 140 *state_ = CANCELED; | 157 *state_ = CANCELED; |
| 141 InterstitialPage::DontProceed(); | |
| 142 } | 158 } |
| 143 virtual void Proceed() { | 159 void OnProceed() { |
| 144 if (state_) | 160 if (state_) |
| 145 *state_ = OKED; | 161 *state_ = OKED; |
| 146 InterstitialPage::Proceed(); | |
| 147 } | 162 } |
| 148 | 163 |
| 149 int command_received_count() const { | 164 int command_received_count() const { |
| 150 return command_received_count_; | 165 return command_received_count_; |
| 151 } | 166 } |
| 152 | 167 |
| 153 void TestDomOperationResponse(const std::string& json_string) { | 168 void TestDomOperationResponse(const std::string& json_string) { |
| 154 if (enabled()) | 169 if (enabled()) |
| 155 CommandReceived(json_string); | 170 CommandReceived(); |
| 156 } | 171 } |
| 157 | 172 |
| 158 void TestDidNavigate(int page_id, const GURL& url) { | 173 void TestDidNavigate(int page_id, const GURL& url) { |
| 159 ViewHostMsg_FrameNavigate_Params params; | 174 ViewHostMsg_FrameNavigate_Params params; |
| 160 InitNavigateParams(¶ms, page_id, url, content::PAGE_TRANSITION_TYPED); | 175 InitNavigateParams(¶ms, page_id, url, content::PAGE_TRANSITION_TYPED); |
| 161 DidNavigate(render_view_host(), params); | 176 DidNavigate(render_view_host(), params); |
| 162 } | 177 } |
| 163 | 178 |
| 164 void TestRenderViewGone(base::TerminationStatus status, int error_code) { | 179 void TestRenderViewGone(base::TerminationStatus status, int error_code) { |
| 165 RenderViewGone(render_view_host(), status, error_code); | 180 RenderViewGone(render_view_host(), status, error_code); |
| 166 } | 181 } |
| 167 | 182 |
| 168 bool is_showing() const { | 183 bool is_showing() const { |
| 169 return static_cast<TestRenderWidgetHostView*>(render_view_host()->view())-> | 184 return static_cast<TestRenderWidgetHostView*>(render_view_host()->view())-> |
| 170 is_showing(); | 185 is_showing(); |
| 171 } | 186 } |
| 172 | 187 |
| 173 void ClearStates() { | 188 void ClearStates() { |
| 174 state_ = NULL; | 189 state_ = NULL; |
| 175 deleted_ = NULL; | 190 deleted_ = NULL; |
| 176 delegate_ = NULL; | 191 delegate_ = NULL; |
| 177 } | 192 } |
| 178 | 193 |
| 194 void CommandReceived() { |
| 195 command_received_count_++; |
| 196 } |
| 197 |
| 179 void set_delegate(Delegate* delegate) { | 198 void set_delegate(Delegate* delegate) { |
| 180 delegate_ = delegate; | 199 delegate_ = delegate; |
| 181 } | 200 } |
| 182 | 201 |
| 183 protected: | 202 protected: |
| 184 virtual RenderViewHost* CreateRenderViewHost() { | 203 virtual RenderViewHost* CreateRenderViewHost() OVERRIDE { |
| 185 return new TestRenderViewHost( | 204 return new TestRenderViewHost( |
| 186 SiteInstance::Create(tab()->GetBrowserContext()), | 205 SiteInstance::Create(tab()->GetBrowserContext()), |
| 187 this, MSG_ROUTING_NONE); | 206 this, MSG_ROUTING_NONE); |
| 188 } | 207 } |
| 189 | 208 |
| 190 virtual content::WebContentsView* CreateWebContentsView() { return NULL; } | 209 virtual content::WebContentsView* CreateWebContentsView() OVERRIDE { |
| 191 | 210 return NULL; |
| 192 | |
| 193 virtual void CommandReceived(const std::string& command) { | |
| 194 command_received_count_++; | |
| 195 } | 211 } |
| 196 | 212 |
| 197 private: | 213 private: |
| 198 InterstitialState* state_; | 214 InterstitialState* state_; |
| 199 bool* deleted_; | 215 bool* deleted_; |
| 200 int command_received_count_; | 216 int command_received_count_; |
| 201 Delegate* delegate_; | 217 Delegate* delegate_; |
| 202 }; | 218 }; |
| 203 | 219 |
| 220 void TestInterstitialPageDelegate::CommandReceived(const std::string& command) { |
| 221 interstitial_page_->CommandReceived(); |
| 222 } |
| 223 |
| 224 void TestInterstitialPageDelegate::OnDontProceed() { |
| 225 interstitial_page_->OnDontProceed(); |
| 226 } |
| 227 |
| 228 void TestInterstitialPageDelegate::OnProceed() { |
| 229 interstitial_page_->OnProceed(); |
| 230 } |
| 231 |
| 204 class TestInterstitialPageStateGuard : public TestInterstitialPage::Delegate { | 232 class TestInterstitialPageStateGuard : public TestInterstitialPage::Delegate { |
| 205 public: | 233 public: |
| 206 explicit TestInterstitialPageStateGuard( | 234 explicit TestInterstitialPageStateGuard( |
| 207 TestInterstitialPage* interstitial_page) | 235 TestInterstitialPage* interstitial_page) |
| 208 : interstitial_page_(interstitial_page) { | 236 : interstitial_page_(interstitial_page) { |
| 209 DCHECK(interstitial_page_); | 237 DCHECK(interstitial_page_); |
| 210 interstitial_page_->set_delegate(this); | 238 interstitial_page_->set_delegate(this); |
| 211 } | 239 } |
| 212 ~TestInterstitialPageStateGuard() { | 240 ~TestInterstitialPageStateGuard() { |
| 213 if (interstitial_page_) | 241 if (interstitial_page_) |
| (...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 | 1886 |
| 1859 // It should have a transient entry. | 1887 // It should have a transient entry. |
| 1860 EXPECT_TRUE(other_controller.GetTransientEntry()); | 1888 EXPECT_TRUE(other_controller.GetTransientEntry()); |
| 1861 | 1889 |
| 1862 // And the interstitial should be showing. | 1890 // And the interstitial should be showing. |
| 1863 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); | 1891 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); |
| 1864 | 1892 |
| 1865 // And the interstitial should do a reload on don't proceed. | 1893 // And the interstitial should do a reload on don't proceed. |
| 1866 EXPECT_TRUE(other_contents->GetInterstitialPage()->reload_on_dont_proceed()); | 1894 EXPECT_TRUE(other_contents->GetInterstitialPage()->reload_on_dont_proceed()); |
| 1867 } | 1895 } |
| OLD | NEW |