Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/macros.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 7 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 8 #include "blimp/client/core/blimp_contents_impl.h" | 10 #include "blimp/client/core/blimp_contents_impl.h" |
| 9 #include "blimp/client/core/public/blimp_contents_observer.h" | 11 #include "blimp/client/core/public/blimp_contents_observer.h" |
| 12 #include "blimp/client/feature/mock_navigation_feature.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 14 |
| 12 namespace blimp { | 15 namespace blimp { |
| 13 namespace client { | 16 namespace client { |
| 14 namespace { | 17 namespace { |
| 15 | 18 |
| 16 const GURL kExampleURL = GURL("https://www.example.com/"); | 19 const GURL kExampleURL = GURL("https://www.example.com/"); |
| 17 const GURL kOtherExampleURL = GURL("https://www.otherexample.com/"); | 20 const GURL kOtherExampleURL = GURL("https://www.otherexample.com/"); |
| 18 | 21 |
| 19 class TestBlimpContentsObserver : public BlimpContentsObserver { | 22 class TestBlimpContentsObserver : public BlimpContentsObserver { |
| 20 public: | 23 public: |
| 21 TestBlimpContentsObserver() = default; | 24 TestBlimpContentsObserver() = default; |
| 22 ~TestBlimpContentsObserver() override = default; | 25 ~TestBlimpContentsObserver() override = default; |
| 23 | 26 |
| 24 void OnURLUpdated(const GURL& url) override { last_url_ = url; } | 27 void OnURLUpdated(const GURL& url) override { last_url_ = url; } |
| 25 | 28 |
| 26 GURL GetLastURL() { return last_url_; } | 29 GURL GetLastURL() { return last_url_; } |
| 27 | 30 |
| 28 private: | 31 private: |
| 29 GURL last_url_; | 32 GURL last_url_; |
| 30 | 33 |
| 31 DISALLOW_COPY_AND_ASSIGN(TestBlimpContentsObserver); | 34 DISALLOW_COPY_AND_ASSIGN(TestBlimpContentsObserver); |
| 32 }; | 35 }; |
| 33 | 36 |
| 37 class TestBlimpNavigationControllerDelegate | |
| 38 : public BlimpNavigationControllerDelegate { | |
| 39 public: | |
| 40 TestBlimpNavigationControllerDelegate() = default; | |
| 41 ~TestBlimpNavigationControllerDelegate() override = default; | |
| 42 | |
| 43 private: | |
| 44 void OnUrlChanged(const GURL& url) override {} | |
|
David Trainor- moved to gerrit
2016/06/29 17:27:15
// BlimpNavigationControllerDelegate implementatio
shaktisahu
2016/07/19 21:45:29
Done.
| |
| 45 void OnFaviconChanged(const SkBitmap& favicon) override {} | |
| 46 void OnTitleChanged(const std::string& title) override {} | |
| 47 void OnLoadingChanged(bool loading) override {} | |
| 48 void OnPageLoadStatusUpdate(bool completed) override {} | |
| 49 DISALLOW_COPY_AND_ASSIGN(TestBlimpNavigationControllerDelegate); | |
|
David Trainor- moved to gerrit
2016/06/29 17:27:15
New line before this?
shaktisahu
2016/07/19 21:45:29
Done.
| |
| 50 }; | |
| 51 | |
| 34 TEST(BlimpContentsImplTest, Basic) { | 52 TEST(BlimpContentsImplTest, Basic) { |
| 35 base::MessageLoop loop; | 53 base::MessageLoop loop; |
| 36 BlimpContentsImpl blimp_contents; | 54 BlimpContentsImpl blimp_contents; |
| 37 | 55 |
| 38 BlimpNavigationController& navigation_controller = | 56 BlimpNavigationController& navigation_controller = |
| 39 blimp_contents.GetNavigationController(); | 57 blimp_contents.GetNavigationController(); |
| 40 | 58 |
| 41 TestBlimpContentsObserver observer1; | 59 TestBlimpContentsObserver observer1; |
| 42 blimp_contents.AddObserver(&observer1); | 60 blimp_contents.AddObserver(&observer1); |
| 43 TestBlimpContentsObserver observer2; | 61 TestBlimpContentsObserver observer2; |
| 44 blimp_contents.AddObserver(&observer2); | 62 blimp_contents.AddObserver(&observer2); |
| 45 | 63 |
| 64 BlimpNavigationControllerImpl* nav_controller_impl = | |
| 65 static_cast<BlimpNavigationControllerImpl*>(&navigation_controller); | |
| 66 MockNavigationFeature feature; | |
| 67 feature.SetDelegate(1, nav_controller_impl); | |
| 68 nav_controller_impl->SetNavigationFeatureForTesting(&feature); | |
| 69 | |
| 46 navigation_controller.LoadURL(kExampleURL); | 70 navigation_controller.LoadURL(kExampleURL); |
| 47 loop.RunUntilIdle(); | 71 loop.RunUntilIdle(); |
| 48 | 72 |
| 49 EXPECT_EQ(kExampleURL, navigation_controller.GetURL()); | 73 EXPECT_EQ(kExampleURL, navigation_controller.GetURL()); |
| 50 EXPECT_EQ(kExampleURL, observer1.GetLastURL()); | 74 EXPECT_EQ(kExampleURL, observer1.GetLastURL()); |
| 51 EXPECT_EQ(kExampleURL, observer2.GetLastURL()); | 75 EXPECT_EQ(kExampleURL, observer2.GetLastURL()); |
| 52 | 76 |
| 53 // Observer should no longer receive callbacks. | 77 // Observer should no longer receive callbacks. |
| 54 blimp_contents.RemoveObserver(&observer1); | 78 blimp_contents.RemoveObserver(&observer1); |
| 55 | 79 |
| 56 navigation_controller.LoadURL(kOtherExampleURL); | 80 navigation_controller.LoadURL(kOtherExampleURL); |
| 57 loop.RunUntilIdle(); | 81 loop.RunUntilIdle(); |
| 58 | 82 |
| 59 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL()); | 83 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL()); |
| 60 EXPECT_EQ(kExampleURL, observer1.GetLastURL()); | 84 EXPECT_EQ(kExampleURL, observer1.GetLastURL()); |
| 61 EXPECT_EQ(kOtherExampleURL, observer2.GetLastURL()); | 85 EXPECT_EQ(kOtherExampleURL, observer2.GetLastURL()); |
| 62 } | 86 } |
| 63 | 87 |
| 64 } // namespace | 88 } // namespace |
| 65 } // namespace client | 89 } // namespace client |
| 66 } // namespace blimp | 90 } // namespace blimp |
| OLD | NEW |