OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome_frame/test/automation_client_mock.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "chrome/common/automation_messages.h" | |
10 #include "chrome_frame/custom_sync_call_context.h" | |
11 #include "chrome_frame/navigation_constraints.h" | |
12 #include "chrome_frame/test/chrome_frame_test_utils.h" | |
13 #include "chrome_frame/test/test_scrubber.h" | |
14 #include "net/base/net_errors.h" | |
15 | |
16 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING | |
17 #include "testing/gmock_mutant.h" | |
18 | |
19 using testing::_; | |
20 using testing::CreateFunctor; | |
21 using testing::Return; | |
22 | |
23 namespace { | |
24 | |
25 #ifndef NDEBUG | |
26 const base::TimeDelta kChromeLaunchTimeout = base::TimeDelta::FromSeconds(15); | |
27 #else | |
28 const base::TimeDelta kChromeLaunchTimeout = base::TimeDelta::FromSeconds(10); | |
29 #endif | |
30 | |
31 const int kSaneAutomationTimeoutMs = 10 * 1000; | |
32 | |
33 } // namespace | |
34 | |
35 MATCHER_P(LaunchParamProfileEq, profile_name, "Check for profile name") { | |
36 return arg->profile_name().compare(profile_name) == 0; | |
37 } | |
38 | |
39 void MockProxyFactory::GetServerImpl(ChromeFrameAutomationProxy* pxy, | |
40 void* proxy_id, | |
41 AutomationLaunchResult result, | |
42 LaunchDelegate* d, | |
43 ChromeFrameLaunchParams* params, | |
44 void** automation_server_id) { | |
45 *automation_server_id = proxy_id; | |
46 loop_->PostDelayedTask(FROM_HERE, | |
47 base::Bind(&LaunchDelegate::LaunchComplete, | |
48 base::Unretained(d), pxy, result), | |
49 base::TimeDelta::FromMilliseconds(params->launch_timeout()) / 2); | |
50 } | |
51 | |
52 MATCHER_P(MsgType, msg_type, "IPC::Message::type()") { | |
53 const IPC::Message& m = arg; | |
54 return (m.type() == msg_type); | |
55 } | |
56 | |
57 MATCHER_P(EqNavigationInfoUrl, url, "IPC::NavigationInfo matcher") { | |
58 if (url.is_valid() && url != arg.url) | |
59 return false; | |
60 // TODO(stevet): other members | |
61 return true; | |
62 } | |
63 | |
64 // Could be implemented as MockAutomationProxy member (we have WithArgs<>!) | |
65 ACTION_P4(HandleCreateTab, tab_handle, external_tab_container, tab_wnd, | |
66 session_id) { | |
67 // arg0 - message | |
68 // arg1 - callback | |
69 // arg2 - key | |
70 CreateExternalTabContext::output_type input_args(tab_wnd, | |
71 external_tab_container, | |
72 tab_handle, | |
73 session_id); | |
74 CreateExternalTabContext* context = | |
75 reinterpret_cast<CreateExternalTabContext*>(arg1); | |
76 DispatchToMethod(context, &CreateExternalTabContext::Completed, input_args); | |
77 delete context; | |
78 } | |
79 | |
80 ACTION_P4(InitiateNavigation, client, url, referrer, constraints) { | |
81 client->InitiateNavigation(url, referrer, constraints); | |
82 } | |
83 | |
84 // ChromeFrameAutomationClient tests that launch Chrome. | |
85 class CFACWithChrome : public testing::Test { | |
86 protected: | |
87 static void SetUpTestCase(); | |
88 static void TearDownTestCase(); | |
89 | |
90 virtual void SetUp() OVERRIDE; | |
91 virtual void TearDown() OVERRIDE; | |
92 | |
93 static base::FilePath profile_path_; | |
94 scoped_refptr<ChromeFrameAutomationClient> client_; | |
95 scoped_refptr<ChromeFrameLaunchParams> launch_params_; | |
96 chrome_frame_test::TimedMsgLoop loop_; | |
97 }; | |
98 | |
99 // static | |
100 base::FilePath CFACWithChrome::profile_path_; | |
101 | |
102 // static | |
103 void CFACWithChrome::SetUpTestCase() { | |
104 GetChromeFrameProfilePath(L"Adam.N.Epilinter", &profile_path_); | |
105 } | |
106 | |
107 // static | |
108 void CFACWithChrome::TearDownTestCase() { | |
109 profile_path_.clear(); | |
110 } | |
111 | |
112 void CFACWithChrome::SetUp() { | |
113 chrome_frame_test::OverrideDataDirectoryForThisTest(profile_path_.value()); | |
114 client_ = new ChromeFrameAutomationClient(); | |
115 GURL empty; | |
116 launch_params_ = new ChromeFrameLaunchParams( | |
117 empty, empty, profile_path_, profile_path_.BaseName().value(), L"", | |
118 false, false, false); | |
119 launch_params_->set_version_check(false); | |
120 launch_params_->set_launch_timeout(kSaneAutomationTimeoutMs); | |
121 } | |
122 | |
123 void CFACWithChrome::TearDown() { | |
124 client_->Uninitialize(); | |
125 } | |
OLD | NEW |