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

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

Issue 2058263002: Tied up BlimpNavigationController to NavigationFeature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp_core
Patch Set: Addressed code review comments Created 4 years, 5 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/blimp_contents_impl.h" 5 #include "blimp/client/core/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/blimp_contents_impl.h" 8 #include "blimp/client/core/blimp_contents_impl.h"
9 #include "blimp/client/feature/mock_navigation_feature.h"
9 #include "blimp/client/public/blimp_contents_observer.h" 10 #include "blimp/client/public/blimp_contents_observer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace blimp { 13 namespace blimp {
13 namespace client { 14 namespace client {
14 namespace { 15 namespace {
15 16
16 const GURL kExampleURL = GURL("https://www.example.com/"); 17 const GURL kExampleURL = GURL("https://www.example.com/");
17 const GURL kOtherExampleURL = GURL("https://www.otherexample.com/"); 18 const GURL kOtherExampleURL = GURL("https://www.otherexample.com/");
18 19
19 class TestBlimpContentsObserver : public BlimpContentsObserver { 20 class TestBlimpContentsObserver : public BlimpContentsObserver {
20 public: 21 public:
21 TestBlimpContentsObserver() = default; 22 TestBlimpContentsObserver() = default;
22 ~TestBlimpContentsObserver() override = default; 23 ~TestBlimpContentsObserver() override = default;
23 24
24 void OnURLUpdated(const GURL& url) override { last_url_ = url; } 25 void OnURLUpdated(const GURL& url) override { last_url_ = url; }
25 26
26 GURL GetLastURL() { return last_url_; } 27 GURL GetLastURL() { return last_url_; }
27 28
28 private: 29 private:
29 GURL last_url_; 30 GURL last_url_;
30 31
31 DISALLOW_COPY_AND_ASSIGN(TestBlimpContentsObserver); 32 DISALLOW_COPY_AND_ASSIGN(TestBlimpContentsObserver);
32 }; 33 };
33 34
35 class TestBlimpNavigationControllerDelegate
36 : public BlimpNavigationControllerDelegate {
37 public:
38 TestBlimpNavigationControllerDelegate() = default;
39 ~TestBlimpNavigationControllerDelegate() override = default;
40
41 private:
42 void OnNavigationStateChanged() override{};
David Trainor- moved to gerrit 2016/07/25 15:57:31 space after override
shaktisahu 2016/07/26 01:25:27 Done.
43
44 DISALLOW_COPY_AND_ASSIGN(TestBlimpNavigationControllerDelegate);
45 };
46
34 TEST(BlimpContentsImplTest, Basic) { 47 TEST(BlimpContentsImplTest, Basic) {
35 base::MessageLoop loop; 48 base::MessageLoop loop;
36 BlimpContentsImpl blimp_contents; 49 BlimpContentsImpl blimp_contents;
37 50
38 BlimpNavigationController& navigation_controller = 51 BlimpNavigationController& navigation_controller =
39 blimp_contents.GetNavigationController(); 52 blimp_contents.GetNavigationController();
40 53
41 TestBlimpContentsObserver observer1; 54 TestBlimpContentsObserver observer1;
42 blimp_contents.AddObserver(&observer1); 55 blimp_contents.AddObserver(&observer1);
43 TestBlimpContentsObserver observer2; 56 TestBlimpContentsObserver observer2;
44 blimp_contents.AddObserver(&observer2); 57 blimp_contents.AddObserver(&observer2);
45 58
59 BlimpNavigationControllerImpl* nav_controller_impl =
David Trainor- moved to gerrit 2016/07/25 15:57:31 Can we just convert it to an impl when we query it
shaktisahu 2016/07/26 01:25:27 Done.
60 static_cast<BlimpNavigationControllerImpl*>(&navigation_controller);
61 MockNavigationFeature feature;
62 feature.SetDelegate(1, nav_controller_impl);
63 nav_controller_impl->SetNavigationFeatureForTesting(&feature);
64
46 navigation_controller.LoadURL(kExampleURL); 65 navigation_controller.LoadURL(kExampleURL);
47 loop.RunUntilIdle(); 66 loop.RunUntilIdle();
48 67
49 EXPECT_EQ(kExampleURL, navigation_controller.GetURL()); 68 EXPECT_EQ(kExampleURL, navigation_controller.GetURL());
50 EXPECT_EQ(kExampleURL, observer1.GetLastURL()); 69 EXPECT_EQ(kExampleURL, observer1.GetLastURL());
51 EXPECT_EQ(kExampleURL, observer2.GetLastURL()); 70 EXPECT_EQ(kExampleURL, observer2.GetLastURL());
52 71
53 // Observer should no longer receive callbacks. 72 // Observer should no longer receive callbacks.
54 blimp_contents.RemoveObserver(&observer1); 73 blimp_contents.RemoveObserver(&observer1);
55 74
56 navigation_controller.LoadURL(kOtherExampleURL); 75 navigation_controller.LoadURL(kOtherExampleURL);
57 loop.RunUntilIdle(); 76 loop.RunUntilIdle();
58 77
59 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL()); 78 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL());
60 EXPECT_EQ(kExampleURL, observer1.GetLastURL()); 79 EXPECT_EQ(kExampleURL, observer1.GetLastURL());
61 EXPECT_EQ(kOtherExampleURL, observer2.GetLastURL()); 80 EXPECT_EQ(kOtherExampleURL, observer2.GetLastURL());
62 } 81 }
63 82
64 } // namespace 83 } // namespace
65 } // namespace client 84 } // namespace client
66 } // namespace blimp 85 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698