OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "chrome/browser/automation/automation_tab_helper.h" | 8 #include "chrome/browser/automation/automation_tab_helper.h" |
9 #include "chrome/browser/automation/mock_tab_event_observer.h" | 9 #include "chrome/browser/automation/mock_tab_event_observer.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
11 #include "content/public/test/test_browser_thread.h" | 11 #include "content/public/test/test_browser_thread.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using content::BrowserThread; | 15 using content::BrowserThread; |
16 using testing::_; | 16 using testing::_; |
17 | 17 |
18 class AutomationTabHelperTest : public ChromeRenderViewHostTestHarness { | 18 class AutomationTabHelperTest : public ChromeRenderViewHostTestHarness { |
19 public: | 19 public: |
20 AutomationTabHelperTest() | 20 virtual void SetUp() OVERRIDE { |
21 : ChromeRenderViewHostTestHarness(), | |
22 browser_thread_(BrowserThread::UI, &message_loop_) {} | |
23 | |
24 virtual void SetUp() { | |
25 ChromeRenderViewHostTestHarness::SetUp(); | 21 ChromeRenderViewHostTestHarness::SetUp(); |
26 AutomationTabHelper::CreateForWebContents(web_contents()); | 22 AutomationTabHelper::CreateForWebContents(web_contents()); |
27 mock_observer_.StartObserving(tab_helper()); | 23 mock_observer_.StartObserving(tab_helper()); |
28 } | 24 } |
29 | 25 |
30 protected: | 26 protected: |
31 // These are here so that we don't have to add each test as a | 27 // These are here so that we don't have to add each test as a |
32 // |AutomationTabHelper| friend. | 28 // |AutomationTabHelper| friend. |
33 void StartLoading() { | 29 void StartLoading() { |
34 tab_helper()->DidStartLoading(NULL); | 30 tab_helper()->DidStartLoading(NULL); |
(...skipping 12 matching lines...) Expand all Loading... |
47 } | 43 } |
48 | 44 |
49 void CompleteOrCancelClientRedirect(int64 frame_id) { | 45 void CompleteOrCancelClientRedirect(int64 frame_id) { |
50 tab_helper()->OnDidCompleteOrCancelClientRedirect(frame_id); | 46 tab_helper()->OnDidCompleteOrCancelClientRedirect(frame_id); |
51 } | 47 } |
52 | 48 |
53 AutomationTabHelper* tab_helper() { | 49 AutomationTabHelper* tab_helper() { |
54 return AutomationTabHelper::FromWebContents(web_contents()); | 50 return AutomationTabHelper::FromWebContents(web_contents()); |
55 } | 51 } |
56 | 52 |
57 content::TestBrowserThread browser_thread_; | |
58 | |
59 MockTabEventObserver mock_observer_; | 53 MockTabEventObserver mock_observer_; |
60 }; | 54 }; |
61 | 55 |
62 ACTION_P2(CheckHasPendingLoads, tab_helper, has_pending_loads) { | 56 ACTION_P2(CheckHasPendingLoads, tab_helper, has_pending_loads) { |
63 EXPECT_EQ(has_pending_loads, tab_helper->has_pending_loads()); | 57 EXPECT_EQ(has_pending_loads, tab_helper->has_pending_loads()); |
64 } | 58 } |
65 | 59 |
66 TEST_F(AutomationTabHelperTest, AddAndRemoveObserver) { | 60 TEST_F(AutomationTabHelperTest, AddAndRemoveObserver) { |
67 testing::MockFunction<void()> check; | 61 testing::MockFunction<void()> check; |
68 | 62 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 198 |
205 testing::InSequence expect_in_sequence; | 199 testing::InSequence expect_in_sequence; |
206 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())); | 200 EXPECT_CALL(mock_observer_, OnFirstPendingLoad(web_contents())); |
207 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())); | 201 EXPECT_CALL(mock_observer_, OnNoMorePendingLoads(web_contents())); |
208 | 202 |
209 StartLoading(); | 203 StartLoading(); |
210 WillPerformClientRedirect(1); | 204 WillPerformClientRedirect(1); |
211 WebContentsDestroyed(); | 205 WebContentsDestroyed(); |
212 EXPECT_FALSE(tab_helper()->has_pending_loads()); | 206 EXPECT_FALSE(tab_helper()->has_pending_loads()); |
213 } | 207 } |
OLD | NEW |