| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 #include "chrome_frame/test/automation_client_mock.h" | 4 #include "chrome_frame/test/automation_client_mock.h" |
| 5 | 5 |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "chrome_frame/test/chrome_frame_test_utils.h" | 8 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 9 | 9 |
| 10 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING | 10 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING |
| 11 #include "testing/gmock_mutant.h" | 11 #include "testing/gmock_mutant.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 37 *automation_server_id = proxy_id; | 37 *automation_server_id = proxy_id; |
| 38 Task* task = NewRunnableMethod(d, | 38 Task* task = NewRunnableMethod(d, |
| 39 &ProxyFactory::LaunchDelegate::LaunchComplete, pxy, result); | 39 &ProxyFactory::LaunchDelegate::LaunchComplete, pxy, result); |
| 40 loop_->PostDelayedTask(FROM_HERE, task, | 40 loop_->PostDelayedTask(FROM_HERE, task, |
| 41 params.automation_server_launch_timeout/2); | 41 params.automation_server_launch_timeout/2); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void CFACMockTest::SetAutomationServerOk() { | 44 void CFACMockTest::SetAutomationServerOk() { |
| 45 EXPECT_CALL(factory_, GetAutomationServer(testing::NotNull(), | 45 EXPECT_CALL(factory_, GetAutomationServer(testing::NotNull(), |
| 46 testing::Field(&ChromeFrameLaunchParams::profile_name, | 46 testing::Field(&ChromeFrameLaunchParams::profile_name, |
| 47 testing::StrEq(profile_path_.BaseName().ToWStringHack())), | 47 testing::StrEq(profile_)), |
| 48 testing::NotNull())) | 48 testing::NotNull())) |
| 49 .Times(1) | 49 .Times(1) |
| 50 .WillOnce(testing::Invoke(CreateFunctor(&factory_, | 50 .WillOnce(testing::Invoke(CreateFunctor(&factory_, |
| 51 &MockProxyFactory::GetServerImpl, | 51 &MockProxyFactory::GetServerImpl, |
| 52 get_proxy(), id_, | 52 get_proxy(), id_, |
| 53 AUTOMATION_SUCCESS))); | 53 AUTOMATION_SUCCESS))); |
| 54 | 54 |
| 55 EXPECT_CALL(factory_, ReleaseAutomationServer(testing::Eq(id_))).Times(1); | 55 EXPECT_CALL(factory_, ReleaseAutomationServer(testing::Eq(id_))).Times(1); |
| 56 } | 56 } |
| 57 | 57 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 84 c->Run(external_tab_container, tab_wnd, tab_handle); | 84 c->Run(external_tab_container, tab_wnd, tab_handle); |
| 85 delete c; | 85 delete c; |
| 86 delete arg0; | 86 delete arg0; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy | 89 // We mock ChromeFrameDelegate only. The rest is with real AutomationProxy |
| 90 TEST(CFACWithChrome, CreateTooFast) { | 90 TEST(CFACWithChrome, CreateTooFast) { |
| 91 MockCFDelegate cfd; | 91 MockCFDelegate cfd; |
| 92 chrome_frame_test::TimedMsgLoop loop; | 92 chrome_frame_test::TimedMsgLoop loop; |
| 93 int timeout = 0; // Chrome cannot send Hello message so fast. | 93 int timeout = 0; // Chrome cannot send Hello message so fast. |
| 94 const FilePath profile_path( | 94 const std::wstring profile = L"Adam.N.Epilinter"; |
| 95 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | |
| 96 | 95 |
| 97 scoped_refptr<ChromeFrameAutomationClient> client; | 96 scoped_refptr<ChromeFrameAutomationClient> client; |
| 98 client = new ChromeFrameAutomationClient(); | 97 client = new ChromeFrameAutomationClient(); |
| 99 | 98 |
| 100 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) | 99 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(AUTOMATION_TIMEOUT, _)) |
| 101 .Times(1) | 100 .Times(1) |
| 102 .WillOnce(QUIT_LOOP(loop)); | 101 .WillOnce(QUIT_LOOP(loop)); |
| 103 | 102 |
| 104 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile_path, L"", | 103 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); |
| 105 false)); | |
| 106 loop.RunFor(10); | 104 loop.RunFor(10); |
| 107 client->Uninitialize(); | 105 client->Uninitialize(); |
| 108 } | 106 } |
| 109 | 107 |
| 110 // This test may fail if Chrome take more that 10 seconds (timeout var) to | 108 // This test may fail if Chrome take more that 10 seconds (timeout var) to |
| 111 // launch. In this case GMock shall print something like "unexpected call to | 109 // launch. In this case GMock shall print something like "unexpected call to |
| 112 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify | 110 // OnAutomationServerLaunchFailed". I'm yet to find out how to specify |
| 113 // that this is an unexpected call, and still to execute and action. | 111 // that this is an unexpected call, and still to execute and action. |
| 114 TEST(CFACWithChrome, CreateNotSoFast) { | 112 TEST(CFACWithChrome, CreateNotSoFast) { |
| 115 MockCFDelegate cfd; | 113 MockCFDelegate cfd; |
| 116 chrome_frame_test::TimedMsgLoop loop; | 114 chrome_frame_test::TimedMsgLoop loop; |
| 117 const FilePath profile_path( | 115 const std::wstring profile = L"Adam.N.Epilinter"; |
| 118 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | |
| 119 int timeout = 10000; | 116 int timeout = 10000; |
| 120 | 117 |
| 121 scoped_refptr<ChromeFrameAutomationClient> client; | 118 scoped_refptr<ChromeFrameAutomationClient> client; |
| 122 client = new ChromeFrameAutomationClient; | 119 client = new ChromeFrameAutomationClient; |
| 123 | 120 |
| 124 EXPECT_CALL(cfd, OnAutomationServerReady()) | 121 EXPECT_CALL(cfd, OnAutomationServerReady()) |
| 125 .Times(1) | 122 .Times(1) |
| 126 .WillOnce(QUIT_LOOP(loop)); | 123 .WillOnce(QUIT_LOOP(loop)); |
| 127 | 124 |
| 128 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _)) | 125 EXPECT_CALL(cfd, OnAutomationServerLaunchFailed(_, _)) |
| 129 .Times(0); | 126 .Times(0); |
| 130 | 127 |
| 131 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile_path, L"", | 128 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); |
| 132 false)); | |
| 133 | 129 |
| 134 loop.RunFor(11); | 130 loop.RunFor(11); |
| 135 client->Uninitialize(); | 131 client->Uninitialize(); |
| 136 client = NULL; | 132 client = NULL; |
| 137 } | 133 } |
| 138 | 134 |
| 139 TEST(CFACWithChrome, NavigateOk) { | 135 TEST(CFACWithChrome, NavigateOk) { |
| 140 MockCFDelegate cfd; | 136 MockCFDelegate cfd; |
| 141 chrome_frame_test::TimedMsgLoop loop; | 137 chrome_frame_test::TimedMsgLoop loop; |
| 138 const std::wstring profile = L"Adam.N.Epilinter"; |
| 142 const std::string url = "about:version"; | 139 const std::string url = "about:version"; |
| 143 const FilePath profile_path( | |
| 144 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | |
| 145 int timeout = 10000; | 140 int timeout = 10000; |
| 146 | 141 |
| 147 scoped_refptr<ChromeFrameAutomationClient> client; | 142 scoped_refptr<ChromeFrameAutomationClient> client; |
| 148 client = new ChromeFrameAutomationClient; | 143 client = new ChromeFrameAutomationClient; |
| 149 | 144 |
| 150 EXPECT_CALL(cfd, OnAutomationServerReady()) | 145 EXPECT_CALL(cfd, OnAutomationServerReady()) |
| 151 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( | 146 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( |
| 152 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, | 147 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, |
| 153 url, std::string(), false)))); | 148 url, std::string(), false)))); |
| 154 | 149 |
| 155 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); | 150 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); |
| 156 | 151 |
| 157 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)) | 152 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)) |
| 158 .Times(testing::AnyNumber()); | 153 .Times(testing::AnyNumber()); |
| 159 | 154 |
| 160 { | 155 { |
| 161 testing::InSequence s; | 156 testing::InSequence s; |
| 162 | 157 |
| 163 EXPECT_CALL(cfd, OnDidNavigate(_, EqNavigationInfoUrl(GURL()))) | 158 EXPECT_CALL(cfd, OnDidNavigate(_, EqNavigationInfoUrl(GURL()))) |
| 164 .Times(1); | 159 .Times(1); |
| 165 | 160 |
| 166 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(1); | 161 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(1); |
| 167 | 162 |
| 168 EXPECT_CALL(cfd, OnLoad(_, _)) | 163 EXPECT_CALL(cfd, OnLoad(_, _)) |
| 169 .Times(1) | 164 .Times(1) |
| 170 .WillOnce(QUIT_LOOP(loop)); | 165 .WillOnce(QUIT_LOOP(loop)); |
| 171 } | 166 } |
| 172 | 167 |
| 173 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile_path, L"", | 168 EXPECT_TRUE(client->Initialize(&cfd, timeout, false, profile, L"", false)); |
| 174 false)); | |
| 175 loop.RunFor(10); | 169 loop.RunFor(10); |
| 176 client->Uninitialize(); | 170 client->Uninitialize(); |
| 177 client = NULL; | 171 client = NULL; |
| 178 } | 172 } |
| 179 | 173 |
| 180 TEST(CFACWithChrome, NavigateFailed) { | 174 TEST(CFACWithChrome, NavigateFailed) { |
| 181 MockCFDelegate cfd; | 175 MockCFDelegate cfd; |
| 182 chrome_frame_test::TimedMsgLoop loop; | 176 chrome_frame_test::TimedMsgLoop loop; |
| 183 const FilePath profile_path( | 177 const std::wstring profile = L"Adam.N.Epilinter"; |
| 184 chrome_frame_test::GetProfilePath(L"Adam.N.Epilinter")); | |
| 185 const std::string url = "http://127.0.0.3:65412/"; | 178 const std::string url = "http://127.0.0.3:65412/"; |
| 186 const URLRequestStatus connection_failed(URLRequestStatus::FAILED, | 179 const URLRequestStatus connection_failed(URLRequestStatus::FAILED, |
| 187 net::ERR_INVALID_URL); | 180 net::ERR_INVALID_URL); |
| 188 | 181 |
| 189 scoped_refptr<ChromeFrameAutomationClient> client; | 182 scoped_refptr<ChromeFrameAutomationClient> client; |
| 190 client = new ChromeFrameAutomationClient; | 183 client = new ChromeFrameAutomationClient; |
| 191 cfd.SetRequestDelegate(client); | 184 cfd.SetRequestDelegate(client); |
| 192 | 185 |
| 193 EXPECT_CALL(cfd, OnAutomationServerReady()) | 186 EXPECT_CALL(cfd, OnAutomationServerReady()) |
| 194 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( | 187 .WillOnce(testing::IgnoreResult(testing::InvokeWithoutArgs(CreateFunctor( |
| 195 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, | 188 client.get(), &ChromeFrameAutomationClient::InitiateNavigation, |
| 196 url, std::string(), false)))); | 189 url, std::string(), false)))); |
| 197 | 190 |
| 198 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); | 191 EXPECT_CALL(cfd, GetBounds(_)).Times(testing::AnyNumber()); |
| 199 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)).Times(testing::AnyNumber()); | 192 EXPECT_CALL(cfd, OnNavigationStateChanged(_, _)).Times(testing::AnyNumber()); |
| 200 | 193 |
| 201 EXPECT_CALL(cfd, OnRequestStart(_, _, _)) | 194 EXPECT_CALL(cfd, OnRequestStart(_, _, _)) |
| 202 // Often there's another request for the error page | 195 // Often there's another request for the error page |
| 203 .Times(testing::Between(1, 2)) | 196 .Times(testing::Between(1, 2)) |
| 204 .WillRepeatedly(testing::WithArgs<1>(testing::Invoke(CreateFunctor(&cfd, | 197 .WillRepeatedly(testing::WithArgs<1>(testing::Invoke(CreateFunctor(&cfd, |
| 205 &MockCFDelegate::Reply, connection_failed)))); | 198 &MockCFDelegate::Reply, connection_failed)))); |
| 206 | 199 |
| 207 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AnyNumber()); | 200 EXPECT_CALL(cfd, OnUpdateTargetUrl(_, _)).Times(testing::AnyNumber()); |
| 208 EXPECT_CALL(cfd, OnLoad(_, _)).Times(testing::AtMost(1)); | 201 EXPECT_CALL(cfd, OnLoad(_, _)).Times(testing::AtMost(1)); |
| 209 | 202 |
| 210 EXPECT_CALL(cfd, OnNavigationFailed(_, _, GURL(url))) | 203 EXPECT_CALL(cfd, OnNavigationFailed(_, _, GURL(url))) |
| 211 .Times(1) | 204 .Times(1) |
| 212 .WillOnce(QUIT_LOOP_SOON(loop, 2)); | 205 .WillOnce(QUIT_LOOP_SOON(loop, 2)); |
| 213 | 206 |
| 214 EXPECT_TRUE(client->Initialize(&cfd, 10000, false, profile_path, L"", | 207 EXPECT_TRUE(client->Initialize(&cfd, 10000, false, profile, L"", false)); |
| 215 false)); | |
| 216 | 208 |
| 217 loop.RunFor(10); | 209 loop.RunFor(10); |
| 218 client->Uninitialize(); | 210 client->Uninitialize(); |
| 219 client = NULL; | 211 client = NULL; |
| 220 } | 212 } |
| 221 | 213 |
| 222 TEST_F(CFACMockTest, MockedCreateTabOk) { | 214 TEST_F(CFACMockTest, MockedCreateTabOk) { |
| 223 int timeout = 500; | 215 int timeout = 500; |
| 224 CreateTab(); | 216 CreateTab(); |
| 225 SetAutomationServerOk(); | 217 SetAutomationServerOk(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 238 | 230 |
| 239 EXPECT_CALL(proxy_, CreateTabProxy(testing::Eq(tab_handle_))) | 231 EXPECT_CALL(proxy_, CreateTabProxy(testing::Eq(tab_handle_))) |
| 240 .WillOnce(testing::Return(tab_)); | 232 .WillOnce(testing::Return(tab_)); |
| 241 | 233 |
| 242 EXPECT_CALL(cfd_, OnAutomationServerReady()) | 234 EXPECT_CALL(cfd_, OnAutomationServerReady()) |
| 243 .WillOnce(QUIT_LOOP(loop_)); | 235 .WillOnce(QUIT_LOOP(loop_)); |
| 244 | 236 |
| 245 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); | 237 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); |
| 246 | 238 |
| 247 // Here we go! | 239 // Here we go! |
| 248 EXPECT_TRUE(client_->Initialize(&cfd_, timeout, false, profile_path_, L"", | 240 EXPECT_TRUE(client_->Initialize(&cfd_, timeout, false, profile_, L"", false)); |
| 249 false)); | |
| 250 loop_.RunFor(10); | 241 loop_.RunFor(10); |
| 251 client_->Uninitialize(); | 242 client_->Uninitialize(); |
| 252 } | 243 } |
| 253 | 244 |
| 254 TEST_F(CFACMockTest, MockedCreateTabFailed) { | 245 TEST_F(CFACMockTest, MockedCreateTabFailed) { |
| 255 HWND null_wnd = NULL; | 246 HWND null_wnd = NULL; |
| 256 SetAutomationServerOk(); | 247 SetAutomationServerOk(); |
| 257 | 248 |
| 258 EXPECT_CALL(proxy_, server_version()).Times(testing::AnyNumber()) | 249 EXPECT_CALL(proxy_, server_version()).Times(testing::AnyNumber()) |
| 259 .WillRepeatedly(testing::Return("")); | 250 .WillRepeatedly(testing::Return("")); |
| 260 | 251 |
| 261 EXPECT_CALL(proxy_, SendAsAsync(testing::Property(&IPC::SyncMessage::type, | 252 EXPECT_CALL(proxy_, SendAsAsync(testing::Property(&IPC::SyncMessage::type, |
| 262 AutomationMsg_CreateExternalTab__ID), | 253 AutomationMsg_CreateExternalTab__ID), |
| 263 testing::NotNull(), _)) | 254 testing::NotNull(), _)) |
| 264 .Times(1) | 255 .Times(1) |
| 265 .WillOnce(HandleCreateTab(tab_handle_, null_wnd, null_wnd)); | 256 .WillOnce(HandleCreateTab(tab_handle_, null_wnd, null_wnd)); |
| 266 | 257 |
| 267 EXPECT_CALL(proxy_, CreateTabProxy(_)).Times(0); | 258 EXPECT_CALL(proxy_, CreateTabProxy(_)).Times(0); |
| 268 | 259 |
| 269 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); | 260 EXPECT_CALL(proxy_, CancelAsync(_)).Times(testing::AnyNumber()); |
| 270 | 261 |
| 271 Set_CFD_LaunchFailed(AUTOMATION_CREATE_TAB_FAILED); | 262 Set_CFD_LaunchFailed(AUTOMATION_CREATE_TAB_FAILED); |
| 272 | 263 |
| 273 // Here we go! | 264 // Here we go! |
| 274 EXPECT_TRUE(client_->Initialize(&cfd_, timeout_, false, profile_path_, L"", | 265 EXPECT_TRUE(client_->Initialize(&cfd_, timeout_, false, profile_, L"", |
| 275 false)); | 266 false)); |
| 276 loop_.RunFor(4); | 267 loop_.RunFor(4); |
| 277 client_->Uninitialize(); | 268 client_->Uninitialize(); |
| 278 } | 269 } |
| 279 | 270 |
| OLD | NEW |