OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
jam
2013/05/31 17:29:25
i think this is a merge conflict, this file is gon
awong
2013/05/31 20:57:17
Done.
| |
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 <map> | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "chrome/browser/automation/automation_tab_helper.h" | |
9 #include "chrome/browser/automation/mock_tab_event_observer.h" | |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
11 #include "content/public/test/test_browser_thread.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 using content::BrowserThread; | |
16 using testing::_; | |
17 | |
18 class AutomationTabHelperTest : public ChromeRenderViewHostTestHarness { | |
19 public: | |
20 virtual void SetUp() OVERRIDE { | |
21 ChromeRenderViewHostTestHarness::SetUp(); | |
22 AutomationTabHelper::CreateForWebContents(web_contents()); | |
23 mock_observer_.StartObserving(tab_helper()); | |
24 } | |
25 | |
26 protected: | |
27 // These are here so that we don't have to add each test as a | |
28 // |AutomationTabHelper| friend. | |
29 void StartLoading() { | |
30 tab_helper()->DidStartLoading(NULL); | |
31 } | |
32 | |
33 void StopLoading() { | |
34 tab_helper()->DidStopLoading(NULL); | |
35 } | |
36 | |
37 void WebContentsDestroyed() { | |
38 tab_helper()->WebContentsDestroyed(web_contents()); | |
39 } | |
40 | |
41 void WillPerformClientRedirect(int64 frame_id) { | |
42 tab_helper()->OnWillPerformClientRedirect(frame_id, 0); | |
43 } | |
44 | |
45 void CompleteOrCancelClientRedirect(int64 frame_id) { | |
46 tab_helper()->OnDidCompleteOrCancelClientRedirect(frame_id); | |
47 } | |
48 | |
49 AutomationTabHelper* tab_helper() { | |
50 return AutomationTabHelper::FromWebContents(web_contents()); | |
51 } | |
52 | |
53 MockTabEventObserver mock_observer_; | |
54 }; | |
55 | |
56 ACTION_P2(CheckHasPendingLoads, tab_helper, has_pending_loads) { | |
57 EXPECT_EQ(has_pending_loads, tab_helper->has_pending_loads()); | |
58 } | |
59 | |
60 TEST_F(AutomationTabHelperTest, AddAndRemoveObserver) { | |
61 testing::MockFunction<void()> check; | |
62 | |
63 { | |
64 testing::InSequence expect_in_sequence; | |
65 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(_)); | |
66 EXPECT_CALL(check, Call()); | |
67 } | |
68 | |
69 StartLoading(); | |
70 check.Call(); | |
71 tab_helper()->RemoveObserver(&mock_observer_); | |
72 StartLoading(); | |
73 } | |
74 | |
75 TEST_F(AutomationTabHelperTest, StartStopLoading) { | |
76 testing::MockFunction<void()> check; | |
77 | |
78 testing::InSequence expect_in_sequence; | |
79 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())) | |
80 .WillOnce(CheckHasPendingLoads(tab_helper(), true)); | |
81 EXPECT_CALL(check, Call()); | |
82 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())) | |
83 .WillOnce(CheckHasPendingLoads(tab_helper(), false)); | |
84 | |
85 EXPECT_FALSE(tab_helper()->has_pending_loads()); | |
86 StartLoading(); | |
87 EXPECT_TRUE(tab_helper()->has_pending_loads()); | |
88 check.Call(); | |
89 StopLoading(); | |
90 EXPECT_FALSE(tab_helper()->has_pending_loads()); | |
91 } | |
92 | |
93 TEST_F(AutomationTabHelperTest, DuplicateLoads) { | |
94 testing::InSequence expect_in_sequence; | |
95 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())); | |
96 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())); | |
97 | |
98 StartLoading(); | |
99 StartLoading(); | |
100 StopLoading(); | |
101 StopLoading(); | |
102 } | |
103 | |
104 TEST_F(AutomationTabHelperTest, ClientRedirect) { | |
105 testing::MockFunction<void()> check; | |
106 | |
107 testing::InSequence expect_in_sequence; | |
108 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())) | |
109 .WillOnce(CheckHasPendingLoads(tab_helper(), true)); | |
110 EXPECT_CALL(check, Call()); | |
111 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())) | |
112 .WillOnce(CheckHasPendingLoads(tab_helper(), false)); | |
113 | |
114 WillPerformClientRedirect(1); | |
115 EXPECT_TRUE(tab_helper()->has_pending_loads()); | |
116 check.Call(); | |
117 CompleteOrCancelClientRedirect(1); | |
118 EXPECT_FALSE(tab_helper()->has_pending_loads()); | |
119 } | |
120 | |
121 TEST_F(AutomationTabHelperTest, DiscardExtraClientRedirects) { | |
122 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())); | |
123 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())); | |
124 | |
125 WillPerformClientRedirect(1); | |
126 WillPerformClientRedirect(1); | |
127 CompleteOrCancelClientRedirect(1); | |
128 EXPECT_FALSE(tab_helper()->has_pending_loads()); | |
129 CompleteOrCancelClientRedirect(1); | |
130 CompleteOrCancelClientRedirect(2); | |
131 } | |
132 | |
133 TEST_F(AutomationTabHelperTest, StartStopLoadingWithClientRedirect) { | |
134 testing::MockFunction<void()> check; | |
135 | |
136 testing::InSequence expect_in_sequence; | |
137 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())); | |
138 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())); | |
139 | |
140 StartLoading(); | |
141 WillPerformClientRedirect(1); | |
142 CompleteOrCancelClientRedirect(1); | |
143 StopLoading(); | |
144 } | |
145 | |
146 TEST_F(AutomationTabHelperTest, ClientRedirectBeforeLoad) { | |
147 testing::MockFunction<void()> check; | |
148 | |
149 testing::InSequence expect_in_sequence; | |
150 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())); | |
151 EXPECT_CALL(check, Call()); | |
152 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())); | |
153 | |
154 StartLoading(); | |
155 WillPerformClientRedirect(1); | |
156 CompleteOrCancelClientRedirect(1); | |
157 EXPECT_TRUE(tab_helper()->has_pending_loads()); | |
158 check.Call(); | |
159 StopLoading(); | |
160 } | |
161 | |
162 TEST_F(AutomationTabHelperTest, ClientRedirectAfterLoad) { | |
163 testing::MockFunction<void()> check; | |
164 | |
165 testing::InSequence expect_in_sequence; | |
166 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())); | |
167 EXPECT_CALL(check, Call()); | |
168 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())); | |
169 | |
170 StartLoading(); | |
171 WillPerformClientRedirect(1); | |
172 StopLoading(); | |
173 EXPECT_TRUE(tab_helper()->has_pending_loads()); | |
174 check.Call(); | |
175 CompleteOrCancelClientRedirect(1); | |
176 EXPECT_FALSE(tab_helper()->has_pending_loads()); | |
177 } | |
178 | |
179 TEST_F(AutomationTabHelperTest, AllFramesMustFinishRedirects) { | |
180 testing::MockFunction<void()> check; | |
181 | |
182 testing::InSequence expect_in_sequence; | |
183 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())); | |
184 EXPECT_CALL(check, Call()); | |
185 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())); | |
186 | |
187 WillPerformClientRedirect(1); | |
188 WillPerformClientRedirect(2); | |
189 CompleteOrCancelClientRedirect(1); | |
190 check.Call(); | |
191 EXPECT_TRUE(tab_helper()->has_pending_loads()); | |
192 CompleteOrCancelClientRedirect(2); | |
193 EXPECT_FALSE(tab_helper()->has_pending_loads()); | |
194 } | |
195 | |
196 TEST_F(AutomationTabHelperTest, DestroyedTabStopsLoading) { | |
197 testing::MockFunction<void()> check; | |
198 | |
199 testing::InSequence expect_in_sequence; | |
200 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())); | |
201 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())); | |
202 | |
203 StartLoading(); | |
204 WillPerformClientRedirect(1); | |
205 WebContentsDestroyed(); | |
206 EXPECT_FALSE(tab_helper()->has_pending_loads()); | |
207 } | |
OLD | NEW |