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

Side by Side Diff: blimp/client/core/contents/blimp_contents_impl_unittest.cc

Issue 2201433002: Migrate TabControlFeature from 0.5 to 0.6 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git add blimp/client/public/contents/blimp_contents_observer.cc Created 4 years, 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "blimp/client/core/contents/blimp_contents_impl.h" 5 #include "blimp/client/core/contents/blimp_contents_impl.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "blimp/client/core/contents/blimp_contents_impl.h" 8 #include "blimp/client/core/contents/blimp_contents_impl.h"
9 #include "blimp/client/core/contents/fake_navigation_feature.h" 9 #include "blimp/client/core/contents/fake_navigation_feature.h"
10 #include "blimp/client/public/contents/blimp_contents_observer.h" 10 #include "blimp/client/public/contents/blimp_contents_observer.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace blimp { 14 namespace blimp {
15 namespace client { 15 namespace client {
16 namespace { 16 namespace {
17 17
18 const char kExampleURL[] = "https://www.example.com/"; 18 const char kExampleURL[] = "https://www.example.com/";
19 const char kOtherExampleURL[] = "https://www.otherexample.com/"; 19 const char kOtherExampleURL[] = "https://www.otherexample.com/";
20 const int kDummyTabId = 0;
20 21
21 class MockBlimpContentsObserver : public BlimpContentsObserver { 22 class MockBlimpContentsObserver : public BlimpContentsObserver {
22 public: 23 public:
23 MockBlimpContentsObserver() = default; 24 explicit MockBlimpContentsObserver(BlimpContents* blimp_contents)
25 : BlimpContentsObserver(blimp_contents) {}
24 ~MockBlimpContentsObserver() override = default; 26 ~MockBlimpContentsObserver() override = default;
25 27
26 MOCK_METHOD0(OnNavigationStateChanged, void()); 28 MOCK_METHOD0(OnNavigationStateChanged, void());
27 29
28 private: 30 private:
29 DISALLOW_COPY_AND_ASSIGN(MockBlimpContentsObserver); 31 DISALLOW_COPY_AND_ASSIGN(MockBlimpContentsObserver);
30 }; 32 };
31 33
32 TEST(BlimpContentsImplTest, LoadURLAndNotifyObservers) { 34 TEST(BlimpContentsImplTest, LoadURLAndNotifyObservers) {
33 base::MessageLoop loop; 35 base::MessageLoop loop;
34 BlimpContentsImpl blimp_contents; 36 BlimpContentsImpl blimp_contents{kDummyTabId};
nyquist 2016/08/05 23:03:23 I think we often use just () for constructors. Is
Menglin 2016/08/06 00:57:00 use () instead
35 37
36 BlimpNavigationControllerImpl& navigation_controller = 38 BlimpNavigationControllerImpl& navigation_controller =
37 blimp_contents.GetNavigationController(); 39 blimp_contents.GetNavigationController();
38 FakeNavigationFeature feature; 40 FakeNavigationFeature feature;
39 feature.SetDelegate(1, &navigation_controller); 41 feature.SetDelegate(1, &navigation_controller);
40 navigation_controller.SetNavigationFeatureForTesting(&feature); 42 navigation_controller.SetNavigationFeatureForTesting(&feature);
41 43
42 testing::StrictMock<MockBlimpContentsObserver> observer1; 44 testing::StrictMock<MockBlimpContentsObserver> observer1(&blimp_contents);
43 blimp_contents.AddObserver(&observer1); 45 testing::StrictMock<MockBlimpContentsObserver> observer2(&blimp_contents);
44 testing::StrictMock<MockBlimpContentsObserver> observer2;
45 blimp_contents.AddObserver(&observer2);
46 46
47 EXPECT_CALL(observer1, OnNavigationStateChanged()); 47 EXPECT_CALL(observer1, OnNavigationStateChanged());
48 EXPECT_CALL(observer2, OnNavigationStateChanged()).Times(2); 48 EXPECT_CALL(observer2, OnNavigationStateChanged()).Times(2);
49 49
50 navigation_controller.LoadURL(GURL(kExampleURL)); 50 navigation_controller.LoadURL(GURL(kExampleURL));
51 loop.RunUntilIdle(); 51 loop.RunUntilIdle();
52 52
53 EXPECT_EQ(kExampleURL, navigation_controller.GetURL().spec()); 53 EXPECT_EQ(kExampleURL, navigation_controller.GetURL().spec());
54 54
55 // Observer should no longer receive callbacks. 55 // Observer should no longer receive callbacks.
56 blimp_contents.RemoveObserver(&observer1); 56 blimp_contents.RemoveObserver(&observer1);
57 57
58 navigation_controller.LoadURL(GURL(kOtherExampleURL)); 58 navigation_controller.LoadURL(GURL(kOtherExampleURL));
59 loop.RunUntilIdle(); 59 loop.RunUntilIdle();
60 60
61 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL().spec()); 61 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL().spec());
62 } 62 }
63 63
64 } // namespace 64 } // namespace
65 } // namespace client 65 } // namespace client
66 } // namespace blimp 66 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698