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

Side by Side Diff: services/navigation/navigation_unittest.cc

Issue 2046723002: Add navigation client lib for convenience (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@target
Patch Set: Created 4 years, 6 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
« no previous file with comments | « services/navigation/BUILD.gn ('k') | services/navigation/public/cpp/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
OLDNEW
« no previous file with comments | « services/navigation/BUILD.gn ('k') | services/navigation/public/cpp/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698