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

Side by Side Diff: components/web_view/web_view_apptest.cc

Issue 1326443006: mandoline: Add back/forward support and UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actually check the state at the end of CanGoBackAndForward Created 5 years, 3 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 | « components/web_view/url_request_cloneable.cc ('k') | components/web_view/web_view_impl.h » ('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 "components/web_view/public/cpp/web_view.h" 5 #include "components/web_view/public/cpp/web_view.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "components/view_manager/public/cpp/scoped_view_ptr.h" 13 #include "components/view_manager/public/cpp/scoped_view_ptr.h"
14 #include "components/view_manager/public/cpp/tests/view_manager_test_base.h" 14 #include "components/view_manager/public/cpp/tests/view_manager_test_base.h"
15 #include "components/view_manager/public/cpp/view.h" 15 #include "components/view_manager/public/cpp/view.h"
16 #include "components/view_manager/public/cpp/view_tree_connection.h" 16 #include "components/view_manager/public/cpp/view_tree_connection.h"
17 #include "mojo/util/filename_util.h" 17 #include "mojo/util/filename_util.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace web_view { 20 namespace web_view {
21 21
22 namespace {
23 const char kTestOneFile[] = "test_one.html";
24 const char kTestOneTitle[] = "Test Title One";
25 const char kTestTwoFile[] = "test_two.html";
26 const char kTestTwoTitle[] = "Test Title Two";
27 const char kTestThreeFile[] = "test_three.html";
28 const char kTestThreeTitle[] = "Test Title Three";
29 }
30
22 class WebViewTest : public mojo::ViewManagerTestBase, 31 class WebViewTest : public mojo::ViewManagerTestBase,
23 public mojom::WebViewClient { 32 public mojom::WebViewClient {
24 public: 33 public:
25 WebViewTest() : web_view_(this) {} 34 WebViewTest() : web_view_(this) {}
26 ~WebViewTest() override {} 35 ~WebViewTest() override {}
27 36
28 mojom::WebView* web_view() { return web_view_.web_view(); } 37 mojom::WebView* web_view() { return web_view_.web_view(); }
29 38
30 const std::string& last_title() { return last_title_; } 39 const std::string& last_title() { return last_title_; }
40 mojom::ButtonState last_back_button_state() {
41 return last_back_button_state_;
42 }
43 mojom::ButtonState last_forward_button_state() {
44 return last_forward_button_state_;
45 }
31 46
32 void StartNestedRunLoopUntilLoadingDone() { 47 void StartNestedRunLoopUntilLoadingDone() {
33 run_loop_.reset(new base::RunLoop); 48 run_loop_.reset(new base::RunLoop);
34 run_loop_->Run(); 49 run_loop_->Run();
35 } 50 }
36 51
52 void NavigateTo(const std::string& file) {
53 base::FilePath data_file;
54 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_file));
sky 2015/09/11 20:22:51 As you have asserts in here you'll want to wrap ca
55 data_file = data_file.AppendASCII("components")
56 .AppendASCII("test")
57 .AppendASCII("data")
58 .AppendASCII("web_view")
59 .AppendASCII(file);
60 ASSERT_TRUE(base::PathExists(data_file));
61 mojo::URLRequestPtr request(mojo::URLRequest::New());
62 request->url = mojo::util::FilePathToFileURL(data_file).spec();
63 web_view()->LoadRequest(request.Pass());
64 StartNestedRunLoopUntilLoadingDone();
65 }
66
37 private: 67 private:
38 void QuitNestedRunLoop() { 68 void QuitNestedRunLoop() {
39 if (run_loop_) { 69 if (run_loop_) {
40 run_loop_->Quit(); 70 run_loop_->Quit();
41 } 71 }
42 } 72 }
43 73
44 // Overridden from ApplicationDelegate: 74 // Overridden from ApplicationDelegate:
45 void Initialize(mojo::ApplicationImpl* app) override { 75 void Initialize(mojo::ApplicationImpl* app) override {
46 ViewManagerTestBase::Initialize(app); 76 ViewManagerTestBase::Initialize(app);
(...skipping 16 matching lines...) Expand all
63 ViewManagerTestBase::TearDown(); 93 ViewManagerTestBase::TearDown();
64 } 94 }
65 95
66 // Overridden from web_view::mojom::WebViewClient: 96 // Overridden from web_view::mojom::WebViewClient:
67 void TopLevelNavigate(mojo::URLRequestPtr request) override {} 97 void TopLevelNavigate(mojo::URLRequestPtr request) override {}
68 void LoadingStateChanged(bool is_loading) override { 98 void LoadingStateChanged(bool is_loading) override {
69 if (is_loading == false) 99 if (is_loading == false)
70 QuitNestedRunLoop(); 100 QuitNestedRunLoop();
71 } 101 }
72 void ProgressChanged(double progress) override {} 102 void ProgressChanged(double progress) override {}
103 void BackForwardChanged(mojom::ButtonState back_button,
104 mojom::ButtonState forward_button) override {
105 last_back_button_state_ = back_button;
106 last_forward_button_state_ = forward_button;
107 }
73 void TitleChanged(const mojo::String& title) override { 108 void TitleChanged(const mojo::String& title) override {
74 last_title_ = title.get(); 109 last_title_ = title.get();
75 } 110 }
76 111
77 mojo::ApplicationImpl* app_; 112 mojo::ApplicationImpl* app_;
78 113
79 mojo::View* content_; 114 mojo::View* content_;
80 115
81 web_view::WebView web_view_; 116 web_view::WebView web_view_;
82 117
83 scoped_ptr<base::RunLoop> run_loop_; 118 scoped_ptr<base::RunLoop> run_loop_;
84 119
85 std::string last_title_; 120 std::string last_title_;
121 mojom::ButtonState last_back_button_state_;
122 mojom::ButtonState last_forward_button_state_;
86 123
87 DISALLOW_COPY_AND_ASSIGN(WebViewTest); 124 DISALLOW_COPY_AND_ASSIGN(WebViewTest);
88 }; 125 };
89 126
90 TEST_F(WebViewTest, TestTitleChanged) { 127 TEST_F(WebViewTest, TestTitleChanged) {
91 base::FilePath data_file; 128 NavigateTo(kTestOneFile);
92 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_file));
93 data_file = data_file.AppendASCII("components").
94 AppendASCII("test").
95 AppendASCII("data").
96 AppendASCII("web_view").
97 AppendASCII("test_title_changed.html");
98 ASSERT_TRUE(base::PathExists(data_file));
99 129
100 mojo::URLRequestPtr request(mojo::URLRequest::New()); 130 // Our title should have been set on the final.
101 request->url = mojo::util::FilePathToFileURL(data_file).spec(); 131 EXPECT_EQ(kTestOneTitle, last_title());
102 web_view()->LoadRequest(request.Pass()); 132 }
103 133
104 // Build a nested run loop. 134 TEST_F(WebViewTest, CanGoBackAndForward) {
135 NavigateTo(kTestOneFile);
136
137 // We can't go back on first navigation since there's nothing previously on
138 // the stack.
139 EXPECT_EQ(kTestOneTitle, last_title());
140 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
141 last_back_button_state());
142 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
143 last_forward_button_state());
144
145 NavigateTo(kTestTwoFile);
146
147 EXPECT_EQ(kTestTwoTitle, last_title());
148 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state());
149 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
150 last_forward_button_state());
151
152 web_view()->GoBack();
105 StartNestedRunLoopUntilLoadingDone(); 153 StartNestedRunLoopUntilLoadingDone();
106 154
107 // Our title should have been set on the final. 155 EXPECT_EQ(kTestOneTitle, last_title());
108 EXPECT_EQ("Test Title Changed", last_title()); 156 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
157 last_back_button_state());
158 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED,
159 last_forward_button_state());
160
161 web_view()->GoForward();
162 StartNestedRunLoopUntilLoadingDone();
163 EXPECT_EQ(kTestTwoTitle, last_title());
164 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state());
165 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
166 last_forward_button_state());
167 }
168
169 TEST_F(WebViewTest, NavigationClearsForward) {
170 // First navigate somewhere, navigate somewhere else, and go back so we have
171 // one item in the forward stack.
172 NavigateTo(kTestOneFile);
173 NavigateTo(kTestTwoFile);
174
175 web_view()->GoBack();
176 StartNestedRunLoopUntilLoadingDone();
177
178 EXPECT_EQ(kTestOneTitle, last_title());
179 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
180 last_back_button_state());
181 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED,
182 last_forward_button_state());
183
184 // Now make a new navigation to a third file. This should clear the forward
185 // stack.
186 NavigateTo(kTestThreeFile);
187
188 EXPECT_EQ(kTestThreeTitle, last_title());
189 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state());
190 EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
191 last_forward_button_state());
109 } 192 }
110 193
111 } // namespace web_view 194 } // namespace web_view
OLDNEW
« no previous file with comments | « components/web_view/url_request_cloneable.cc ('k') | components/web_view/web_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698