hunspell: Cleanup to fix the header include guards under google/ directory.
[chromium-blink-merge.git] / ios / web / active_state_manager_impl_unittest.mm
blob90afcaf92d595c1fa9ebc915641114fc2692ec51
1 // Copyright 2015 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.
5 #include "ios/web/active_state_manager_impl.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "ios/web/public/active_state_manager.h"
9 #include "ios/web/public/browser_state.h"
10 #include "ios/web/public/test/test_browser_state.h"
11 #include "ios/web/public/test/test_web_thread_bundle.h"
12 #include "ios/web/test/web_test.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h"
17 namespace web {
18 namespace {
20 // A test fixture to test ActiveStateManagerImpl.
21 typedef WebTest ActiveStateManagerImplTest;
23 // An ActiveStateManagerImpl::Observer used for testing purposes.
24 class ActiveStateManagerImplObserver : public ActiveStateManagerImpl::Observer {
25  public:
26   ActiveStateManagerImplObserver() {}
27   virtual ~ActiveStateManagerImplObserver() {}
29   // ActiveStateManagerImpl::Observer implementation.
30   MOCK_METHOD0(OnActive, void());
31   MOCK_METHOD0(OnInactive, void());
32   MOCK_METHOD0(WillBeDestroyed, void());
35 }  // namespace
37 // Tests that an ActiveStateManagerImpl is succesfully created with a
38 // BrowserState and that it can be made active/inactive.
39 TEST_F(ActiveStateManagerImplTest, ActiveState) {
40   ActiveStateManager* active_state_manager =
41       BrowserState::GetActiveStateManager(GetBrowserState());
42   ASSERT_TRUE(active_state_manager);
44   ASSERT_TRUE(active_state_manager->IsActive());
46   active_state_manager->SetActive(true);
47   EXPECT_TRUE(active_state_manager->IsActive());
49   // Make sure it is ok to SetActive(true) on an already active
50   // ActiveStateManager.
51   active_state_manager->SetActive(true);
52   EXPECT_TRUE(active_state_manager->IsActive());
54   active_state_manager->SetActive(false);
55   EXPECT_FALSE(active_state_manager->IsActive());
58 // Tests that ActiveStateManagerImpl::Observer are notified correctly.
59 TEST_F(ActiveStateManagerImplTest, ObserverMethod) {
60   // |GetBrowserState()| already has its ActiveStateManager be active.
61   BrowserState::GetActiveStateManager(GetBrowserState())->SetActive(false);
63   ActiveStateManagerImplObserver observer;
64   TestBrowserState browser_state;
65   ActiveStateManagerImpl* active_state_manager =
66       static_cast<ActiveStateManagerImpl*>(
67           BrowserState::GetActiveStateManager(&browser_state));
70   active_state_manager->AddObserver(&observer);
72   EXPECT_CALL(observer, OnActive()).Times(1);
73   EXPECT_CALL(observer, OnInactive()).Times(1);
74   EXPECT_CALL(observer, WillBeDestroyed()).Times(1);
76   active_state_manager->SetActive(true);
77   active_state_manager->SetActive(false);
78   // There is no need to explicitly remove the observer since it is removed when
79   // |active_state_manager| goes away -- which happens when |browser_state| goes
80   // away.
83 }  // namespace web