OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "services/navigation/public/cpp/view.h" |
| 10 #include "services/navigation/public/cpp/view_delegate.h" |
9 #include "services/navigation/public/interfaces/view.mojom.h" | 11 #include "services/navigation/public/interfaces/view.mojom.h" |
10 #include "services/shell/public/cpp/shell_client.h" | 12 #include "services/shell/public/cpp/shell_client.h" |
11 #include "services/shell/public/cpp/shell_test.h" | 13 #include "services/shell/public/cpp/shell_test.h" |
12 | 14 |
13 namespace navigation { | 15 namespace navigation { |
14 | 16 |
15 class NavigationTest : public shell::test::ShellTest, | 17 class NavigationTest : public shell::test::ShellTest, |
16 public mojom::ViewClient { | 18 public ViewDelegate { |
17 public: | 19 public: |
18 NavigationTest() | 20 NavigationTest() |
19 : shell::test::ShellTest("exe:navigation_unittests"), | 21 : shell::test::ShellTest("exe:navigation_unittests") {} |
20 binding_(this) {} | |
21 ~NavigationTest() override {} | 22 ~NavigationTest() override {} |
22 | 23 |
23 protected: | 24 protected: |
24 void SetUp() override { | 25 void SetUp() override { |
25 shell::test::ShellTest::SetUp(); | 26 shell::test::ShellTest::SetUp(); |
26 window_manager_connection_ = connector()->Connect("mojo:test_wm"); | 27 window_manager_connection_ = connector()->Connect("mojo:test_wm"); |
27 } | |
28 | 28 |
29 mojom::ViewClientPtr GetViewClient() { | 29 view_.reset(new View(this)); |
30 return binding_.CreateInterfacePtrAndBind(); | 30 mojom::ViewFactoryPtr view_factory; |
| 31 connector()->ConnectToInterface("exe:navigation", &view_factory); |
| 32 view_->Init(std::move(view_factory)); |
| 33 } |
| 34 void TearDown() override { |
| 35 view_.reset(); |
| 36 shell::test::ShellTest::TearDown(); |
31 } | 37 } |
32 | 38 |
33 void QuitOnLoadingStateChange(base::RunLoop* loop) { | 39 void QuitOnLoadingStateChange(base::RunLoop* loop) { |
34 loop_ = loop; | 40 loop_ = loop; |
35 } | 41 } |
36 | 42 |
| 43 View* view() { return view_.get(); } |
| 44 |
37 private: | 45 private: |
38 // mojom::ViewClient: | 46 // ViewDelegate: |
39 void LoadingStateChanged(bool is_loading) override { | 47 void LoadingStateChanged(bool is_loading) override { |
40 // Should see loading start, then stop. | 48 // Should see loading start, then stop. |
41 if (++load_count_ == 2 && loop_) | 49 if (++load_count_ == 2 && loop_) |
42 loop_->Quit(); | 50 loop_->Quit(); |
43 } | 51 } |
44 void NavigationStateChanged(const GURL& url, | |
45 const mojo::String& title, | |
46 bool can_go_back, | |
47 bool can_go_forward) override {} | |
48 void LoadProgressChanged(double progress) override {} | |
49 void UpdateHoverURL(const GURL& url) override {} | |
50 void ViewCreated(mojom::ViewPtr, | |
51 mojom::ViewClientRequest, | |
52 bool, | |
53 const gfx::Rect&, | |
54 bool) override {} | |
55 void Close() override {} | |
56 | 52 |
57 int load_count_ = 0; | 53 int load_count_ = 0; |
58 mojo::Binding<mojom::ViewClient> binding_; | 54 std::unique_ptr<View> view_; |
59 base::RunLoop* loop_ = nullptr; | 55 base::RunLoop* loop_ = nullptr; |
60 std::unique_ptr<shell::Connection> window_manager_connection_; | 56 std::unique_ptr<shell::Connection> window_manager_connection_; |
61 | 57 |
62 DISALLOW_COPY_AND_ASSIGN(NavigationTest); | 58 DISALLOW_COPY_AND_ASSIGN(NavigationTest); |
63 }; | 59 }; |
64 | 60 |
65 TEST_F(NavigationTest, Navigate) { | 61 TEST_F(NavigationTest, Navigate) { |
66 mojom::ViewFactoryPtr view_factory; | 62 view()->NavigateTo(GURL("about:blank")); |
67 connector()->ConnectToInterface("exe:navigation", &view_factory); | |
68 | |
69 mojom::ViewPtr view; | |
70 view_factory->CreateView(GetViewClient(), GetProxy(&view)); | |
71 view->NavigateTo(GURL("about:blank")); | |
72 | 63 |
73 base::RunLoop loop; | 64 base::RunLoop loop; |
74 QuitOnLoadingStateChange(&loop); | 65 QuitOnLoadingStateChange(&loop); |
75 loop.Run(); | 66 loop.Run(); |
76 } | 67 } |
77 | 68 |
78 } // namespace navigation | 69 } // namespace navigation |
OLD | NEW |