Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/browser/automation/automation_tab_helper_unittest.cc

Issue 14977013: Delete Automation[Tab/Renderer]Helper and users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update now that 202087 is committed Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 <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 AutomationTabHelperTest()
21 : ChromeRenderViewHostTestHarness(),
22 browser_thread_(BrowserThread::UI, &message_loop_) {}
23
24 virtual void SetUp() {
25 ChromeRenderViewHostTestHarness::SetUp();
26 AutomationTabHelper::CreateForWebContents(web_contents());
27 mock_observer_.StartObserving(tab_helper());
28 }
29
30 protected:
31 // These are here so that we don't have to add each test as a
32 // |AutomationTabHelper| friend.
33 void StartLoading() {
34 tab_helper()->DidStartLoading(NULL);
35 }
36
37 void StopLoading() {
38 tab_helper()->DidStopLoading(NULL);
39 }
40
41 void WebContentsDestroyed() {
42 tab_helper()->WebContentsDestroyed(web_contents());
43 }
44
45 void WillPerformClientRedirect(int64 frame_id) {
46 tab_helper()->OnWillPerformClientRedirect(frame_id, 0);
47 }
48
49 void CompleteOrCancelClientRedirect(int64 frame_id) {
50 tab_helper()->OnDidCompleteOrCancelClientRedirect(frame_id);
51 }
52
53 AutomationTabHelper* tab_helper() {
54 return AutomationTabHelper::FromWebContents(web_contents());
55 }
56
57 content::TestBrowserThread browser_thread_;
58
59 MockTabEventObserver mock_observer_;
60 };
61
62 ACTION_P2(CheckHasPendingLoads, tab_helper, has_pending_loads) {
63 EXPECT_EQ(has_pending_loads, tab_helper->has_pending_loads());
64 }
65
66 TEST_F(AutomationTabHelperTest, AddAndRemoveObserver) {
67 testing::MockFunction<void()> check;
68
69 {
70 testing::InSequence expect_in_sequence;
71 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(_));
72 EXPECT_CALL(check, Call());
73 }
74
75 StartLoading();
76 check.Call();
77 tab_helper()->RemoveObserver(&mock_observer_);
78 StartLoading();
79 }
80
81 TEST_F(AutomationTabHelperTest, StartStopLoading) {
82 testing::MockFunction<void()> check;
83
84 testing::InSequence expect_in_sequence;
85 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents()))
86 .WillOnce(CheckHasPendingLoads(tab_helper(), true));
87 EXPECT_CALL(check, Call());
88 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents()))
89 .WillOnce(CheckHasPendingLoads(tab_helper(), false));
90
91 EXPECT_FALSE(tab_helper()->has_pending_loads());
92 StartLoading();
93 EXPECT_TRUE(tab_helper()->has_pending_loads());
94 check.Call();
95 StopLoading();
96 EXPECT_FALSE(tab_helper()->has_pending_loads());
97 }
98
99 TEST_F(AutomationTabHelperTest, DuplicateLoads) {
100 testing::InSequence expect_in_sequence;
101 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents()));
102 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents()));
103
104 StartLoading();
105 StartLoading();
106 StopLoading();
107 StopLoading();
108 }
109
110 TEST_F(AutomationTabHelperTest, ClientRedirect) {
111 testing::MockFunction<void()> check;
112
113 testing::InSequence expect_in_sequence;
114 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents()))
115 .WillOnce(CheckHasPendingLoads(tab_helper(), true));
116 EXPECT_CALL(check, Call());
117 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents()))
118 .WillOnce(CheckHasPendingLoads(tab_helper(), false));
119
120 WillPerformClientRedirect(1);
121 EXPECT_TRUE(tab_helper()->has_pending_loads());
122 check.Call();
123 CompleteOrCancelClientRedirect(1);
124 EXPECT_FALSE(tab_helper()->has_pending_loads());
125 }
126
127 TEST_F(AutomationTabHelperTest, DiscardExtraClientRedirects) {
128 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents()));
129 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents()));
130
131 WillPerformClientRedirect(1);
132 WillPerformClientRedirect(1);
133 CompleteOrCancelClientRedirect(1);
134 EXPECT_FALSE(tab_helper()->has_pending_loads());
135 CompleteOrCancelClientRedirect(1);
136 CompleteOrCancelClientRedirect(2);
137 }
138
139 TEST_F(AutomationTabHelperTest, StartStopLoadingWithClientRedirect) {
140 testing::MockFunction<void()> check;
141
142 testing::InSequence expect_in_sequence;
143 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents()));
144 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents()));
145
146 StartLoading();
147 WillPerformClientRedirect(1);
148 CompleteOrCancelClientRedirect(1);
149 StopLoading();
150 }
151
152 TEST_F(AutomationTabHelperTest, ClientRedirectBeforeLoad) {
153 testing::MockFunction<void()> check;
154
155 testing::InSequence expect_in_sequence;
156 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents()));
157 EXPECT_CALL(check, Call());
158 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents()));
159
160 StartLoading();
161 WillPerformClientRedirect(1);
162 CompleteOrCancelClientRedirect(1);
163 EXPECT_TRUE(tab_helper()->has_pending_loads());
164 check.Call();
165 StopLoading();
166 }
167
168 TEST_F(AutomationTabHelperTest, ClientRedirectAfterLoad) {
169 testing::MockFunction<void()> check;
170
171 testing::InSequence expect_in_sequence;
172 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents()));
173 EXPECT_CALL(check, Call());
174 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents()));
175
176 StartLoading();
177 WillPerformClientRedirect(1);
178 StopLoading();
179 EXPECT_TRUE(tab_helper()->has_pending_loads());
180 check.Call();
181 CompleteOrCancelClientRedirect(1);
182 EXPECT_FALSE(tab_helper()->has_pending_loads());
183 }
184
185 TEST_F(AutomationTabHelperTest, AllFramesMustFinishRedirects) {
186 testing::MockFunction<void()> check;
187
188 testing::InSequence expect_in_sequence;
189 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents()));
190 EXPECT_CALL(check, Call());
191 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents()));
192
193 WillPerformClientRedirect(1);
194 WillPerformClientRedirect(2);
195 CompleteOrCancelClientRedirect(1);
196 check.Call();
197 EXPECT_TRUE(tab_helper()->has_pending_loads());
198 CompleteOrCancelClientRedirect(2);
199 EXPECT_FALSE(tab_helper()->has_pending_loads());
200 }
201
202 TEST_F(AutomationTabHelperTest, DestroyedTabStopsLoading) {
203 testing::MockFunction<void()> check;
204
205 testing::InSequence expect_in_sequence;
206 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents()));
207 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents()));
208
209 StartLoading();
210 WillPerformClientRedirect(1);
211 WebContentsDestroyed();
212 EXPECT_FALSE(tab_helper()->has_pending_loads());
213 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_tab_helper_browsertest.cc ('k') | chrome/browser/automation/mock_tab_event_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698