OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <atlbase.h> | 5 #include <atlbase.h> |
6 #include <atlapp.h> | 6 #include <atlapp.h> |
7 #include <atlmisc.h> | 7 #include <atlmisc.h> |
8 #include <atlwin.h> | 8 #include <atlwin.h> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/win/registry.h" | 15 #include "base/win/registry.h" |
16 #include "chrome_frame/infobars/infobar_content.h" | 16 #include "chrome_frame/infobars/infobar_content.h" |
17 #include "chrome_frame/ready_mode/internal/ready_mode_state.h" | 17 #include "chrome_frame/ready_mode/internal/ready_mode_state.h" |
18 #include "chrome_frame/ready_mode/internal/ready_prompt_content.h" | 18 #include "chrome_frame/ready_mode/internal/ready_prompt_content.h" |
19 #include "chrome_frame/ready_mode/internal/ready_prompt_window.h" | 19 #include "chrome_frame/ready_mode/internal/ready_prompt_window.h" |
20 #include "chrome_frame/ready_mode/internal/registry_ready_mode_state.h" | 20 #include "chrome_frame/ready_mode/internal/registry_ready_mode_state.h" |
| 21 #include "chrome_frame/ready_mode/internal/url_launcher.h" |
21 #include "chrome_frame/simple_resource_loader.h" | 22 #include "chrome_frame/simple_resource_loader.h" |
22 #include "chrome_frame/test/chrome_frame_test_utils.h" | 23 #include "chrome_frame/test/chrome_frame_test_utils.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 class SetResourceInstance { | 27 class SetResourceInstance { |
27 public: | 28 public: |
28 SetResourceInstance() : res_dll_(NULL), old_res_dll_(NULL) { | 29 SetResourceInstance() : res_dll_(NULL), old_res_dll_(NULL) { |
29 SimpleResourceLoader* loader_instance = SimpleResourceLoader::GetInstance(); | 30 SimpleResourceLoader* loader_instance = SimpleResourceLoader::GetInstance(); |
30 EXPECT_TRUE(loader_instance != NULL); | 31 EXPECT_TRUE(loader_instance != NULL); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 }; // class Frame | 91 }; // class Frame |
91 | 92 |
92 class MockReadyModeState : public ReadyModeState { | 93 class MockReadyModeState : public ReadyModeState { |
93 public: | 94 public: |
94 // ReadyModeState implementation | 95 // ReadyModeState implementation |
95 MOCK_METHOD0(TemporarilyDeclineChromeFrame, void(void)); | 96 MOCK_METHOD0(TemporarilyDeclineChromeFrame, void(void)); |
96 MOCK_METHOD0(PermanentlyDeclineChromeFrame, void(void)); | 97 MOCK_METHOD0(PermanentlyDeclineChromeFrame, void(void)); |
97 MOCK_METHOD0(AcceptChromeFrame, void(void)); | 98 MOCK_METHOD0(AcceptChromeFrame, void(void)); |
98 }; // class MockReadyModeState | 99 }; // class MockReadyModeState |
99 | 100 |
| 101 class MockUrlLauncher : public UrlLauncher { |
| 102 public: |
| 103 // UrlLauncher implementation |
| 104 MOCK_METHOD1(LaunchUrl, void(const std::wstring& url)); |
| 105 }; // class MockUrlLauncher |
| 106 |
100 } // namespace | 107 } // namespace |
101 | 108 |
102 class ReadyPromptTest : public testing::Test { | 109 class ReadyPromptTest : public testing::Test { |
103 public: | 110 public: |
104 ReadyPromptTest() : hwnd_(NULL) {} | 111 ReadyPromptTest() : hwnd_(NULL) {} |
105 | 112 |
106 void SetUp() { | 113 void SetUp() { |
107 hwnd_ = window_.Create(NULL); | 114 hwnd_ = window_.Create(NULL); |
108 EXPECT_TRUE(hwnd_ != NULL); | 115 EXPECT_TRUE(hwnd_ != NULL); |
109 window_.ShowWindow(SW_SHOW); | 116 window_.ShowWindow(SW_SHOW); |
110 EXPECT_TRUE(window_.IsWindowVisible()); | 117 EXPECT_TRUE(window_.IsWindowVisible()); |
111 EXPECT_CALL(frame_, GetFrameWindow()).Times(testing::AnyNumber()) | 118 EXPECT_CALL(frame_, GetFrameWindow()).Times(testing::AnyNumber()) |
112 .WillRepeatedly(testing::Return(hwnd_)); | 119 .WillRepeatedly(testing::Return(hwnd_)); |
113 } | 120 } |
114 | 121 |
115 protected: | 122 protected: |
116 SimpleWindow window_; | 123 SimpleWindow window_; |
117 HWND hwnd_; | 124 HWND hwnd_; |
118 MockInfobarContentFrame frame_; | 125 MockInfobarContentFrame frame_; |
119 SetResourceInstance set_resource_instance_; | 126 SetResourceInstance set_resource_instance_; |
120 }; // class ReadyPromptTest | 127 }; // class ReadyPromptTest |
121 | 128 |
122 class ReadyPromptWindowTest : public ReadyPromptTest { | 129 class ReadyPromptWindowTest : public ReadyPromptTest { |
123 public: | 130 public: |
124 void SetUp() { | 131 void SetUp() { |
125 ReadyPromptTest::SetUp(); | 132 ReadyPromptTest::SetUp(); |
126 | 133 |
127 // owned by ReadyPromptWindow | 134 // owned by ReadyPromptWindow |
128 state_ = new MockReadyModeState(); | 135 state_ = new MockReadyModeState(); |
129 ready_prompt_window_ = (new ReadyPromptWindow())->Initialize(&frame_, | 136 url_launcher_ = new MockUrlLauncher(); |
130 state_); | 137 |
| 138 ready_prompt_window_ = ReadyPromptWindow::CreateInstance( |
| 139 &frame_, state_, url_launcher_); |
131 | 140 |
132 ASSERT_TRUE(ready_prompt_window_ != NULL); | 141 ASSERT_TRUE(ready_prompt_window_ != NULL); |
133 RECT position = {0, 0, 800, 39}; | 142 RECT position = {0, 0, 800, 39}; |
134 ASSERT_TRUE(ready_prompt_window_->SetWindowPos(HWND_TOP, &position, | 143 ASSERT_TRUE(ready_prompt_window_->SetWindowPos(HWND_TOP, &position, |
135 SWP_SHOWWINDOW)); | 144 SWP_SHOWWINDOW)); |
136 } | 145 } |
137 | 146 |
138 protected: | 147 protected: |
139 MockReadyModeState* state_; | 148 MockReadyModeState* state_; |
| 149 MockUrlLauncher* url_launcher_; |
140 base::WeakPtr<ReadyPromptWindow> ready_prompt_window_; | 150 base::WeakPtr<ReadyPromptWindow> ready_prompt_window_; |
141 }; // class ReadyPromptWindowTest | 151 }; // class ReadyPromptWindowTest |
142 | 152 |
143 class ReadyPromptWindowButtonTest : public ReadyPromptWindowTest { | 153 class ReadyPromptWindowButtonTest : public ReadyPromptWindowTest { |
144 public: | 154 public: |
145 void TearDown() { | 155 void TearDown() { |
146 ASSERT_TRUE(ready_prompt_window_ != NULL); | 156 ASSERT_TRUE(ready_prompt_window_ != NULL); |
147 ASSERT_TRUE(ready_prompt_window_->DestroyWindow()); | 157 ASSERT_TRUE(ready_prompt_window_->DestroyWindow()); |
148 ASSERT_TRUE(ready_prompt_window_ == NULL); | 158 ASSERT_TRUE(ready_prompt_window_ == NULL); |
149 ASSERT_FALSE(message_loop_.WasTimedOut()); | 159 ASSERT_FALSE(message_loop_.WasTimedOut()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 EXPECT_CALL(frame_, CloseInfobar()).WillOnce(QUIT_LOOP(message_loop_)); | 215 EXPECT_CALL(frame_, CloseInfobar()).WillOnce(QUIT_LOOP(message_loop_)); |
206 ASSERT_NO_FATAL_FAILURE(message_loop_.RunFor(5)); // seconds | 216 ASSERT_NO_FATAL_FAILURE(message_loop_.RunFor(5)); // seconds |
207 } | 217 } |
208 | 218 |
209 chrome_frame_test::TimedMsgLoop message_loop_; | 219 chrome_frame_test::TimedMsgLoop message_loop_; |
210 }; // class ReadyPromptWindowButtonTest | 220 }; // class ReadyPromptWindowButtonTest |
211 | 221 |
212 TEST_F(ReadyPromptTest, ReadyPromptContentTest) { | 222 TEST_F(ReadyPromptTest, ReadyPromptContentTest) { |
213 // owned by ReadyPromptContent | 223 // owned by ReadyPromptContent |
214 MockReadyModeState* state = new MockReadyModeState(); | 224 MockReadyModeState* state = new MockReadyModeState(); |
215 scoped_ptr<ReadyPromptContent> content_(new ReadyPromptContent(state)); | 225 MockUrlLauncher* url_launcher = new MockUrlLauncher(); |
| 226 |
| 227 scoped_ptr<ReadyPromptContent> content_(new ReadyPromptContent(state, |
| 228 url_launcher)); |
216 | 229 |
217 content_->InstallInFrame(&frame_); | 230 content_->InstallInFrame(&frame_); |
218 | 231 |
219 // Ensure that, if a child is created, it is not visible yet. | 232 // Ensure that, if a child is created, it is not visible yet. |
220 HWND child_hwnd = window_.GetZeroOrOneChildWindows(); | 233 HWND child_hwnd = window_.GetZeroOrOneChildWindows(); |
221 if (child_hwnd != NULL) { | 234 if (child_hwnd != NULL) { |
222 CWindow child(child_hwnd); | 235 CWindow child(child_hwnd); |
223 RECT child_dimensions; | 236 RECT child_dimensions; |
224 EXPECT_TRUE(child.GetClientRect(&child_dimensions)); | 237 EXPECT_TRUE(child.GetClientRect(&child_dimensions)); |
225 EXPECT_FALSE(child.IsWindowVisible() && !::IsRectEmpty(&child_dimensions)); | 238 EXPECT_FALSE(child.IsWindowVisible() && !::IsRectEmpty(&child_dimensions)); |
(...skipping 22 matching lines...) Expand all Loading... |
248 content_.reset(); | 261 content_.reset(); |
249 | 262 |
250 EXPECT_TRUE(window_.GetZeroOrOneChildWindows() == NULL); | 263 EXPECT_TRUE(window_.GetZeroOrOneChildWindows() == NULL); |
251 } | 264 } |
252 | 265 |
253 TEST_F(ReadyPromptWindowTest, Destroy) { | 266 TEST_F(ReadyPromptWindowTest, Destroy) { |
254 // Should delete associated mocks, not invoke on ReadyModeState | 267 // Should delete associated mocks, not invoke on ReadyModeState |
255 ready_prompt_window_->DestroyWindow(); | 268 ready_prompt_window_->DestroyWindow(); |
256 } | 269 } |
257 | 270 |
258 TEST_F(ReadyPromptWindowButtonTest, ClickYes) { | 271 TEST_F(ReadyPromptWindowButtonTest, ClickEnable) { |
259 EXPECT_CALL(*state_, AcceptChromeFrame()); | 272 EXPECT_CALL(*state_, AcceptChromeFrame()); |
260 ASSERT_TRUE(ClickOnCaption(L"&Yes")); | 273 ASSERT_TRUE(ClickOnCaption(L"Enable")); |
261 RunUntilCloseInfobar(); | 274 RunUntilCloseInfobar(); |
262 } | 275 } |
263 | 276 |
264 TEST_F(ReadyPromptWindowButtonTest, ClickRemindMeLater) { | 277 TEST_F(ReadyPromptWindowButtonTest, ClickIgnore) { |
265 EXPECT_CALL(*state_, TemporarilyDeclineChromeFrame()); | 278 EXPECT_CALL(*state_, PermanentlyDeclineChromeFrame()); |
266 ASSERT_TRUE(ClickOnCaption(L"Remind me &Later")); | 279 ASSERT_TRUE(ClickOnCaption(L"Ignore")); |
267 RunUntilCloseInfobar(); | 280 RunUntilCloseInfobar(); |
268 } | 281 } |
269 | 282 |
270 TEST_F(ReadyPromptWindowButtonTest, ClickNo) { | |
271 EXPECT_CALL(*state_, PermanentlyDeclineChromeFrame()); | |
272 ASSERT_TRUE(ClickOnCaption(L"&No")); | |
273 RunUntilCloseInfobar(); | |
274 } | |
275 | |
276 // TODO(erikwright): test WebBrowserAdapter | 283 // TODO(erikwright): test WebBrowserAdapter |
277 // TODO(erikwright): an integration test of ReadyMode::Configure with a mock | 284 // TODO(erikwright): an integration test of ReadyMode::Configure with a mock |
278 // IWebBrowser2? | 285 // IWebBrowser2? |
OLD | NEW |