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

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

Issue 1333963003: mandoline: Set up WebViewTest and add a basic test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gn check. 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/web_view/public/cpp/web_view.h"
6
7 #include "base/base_paths.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
12 #include "base/run_loop.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"
15 #include "components/view_manager/public/cpp/view.h"
16 #include "components/view_manager/public/cpp/view_tree_connection.h"
17 #include "mojo/util/filename_util.h"
18 #include "url/gurl.h"
19
20 namespace web_view {
21
22 class WebViewTest : public mojo::ViewManagerTestBase,
23 public mojom::WebViewClient {
24 public:
25 WebViewTest() : web_view_(this) {}
26 ~WebViewTest() override {}
27
28 mojom::WebView* web_view() { return web_view_.web_view(); }
29
30 const std::string& last_title() { return last_title_; }
31
32 void StartNestedRunLoopUntilLoadingDone() {
33 run_loop_.reset(new base::RunLoop);
34 run_loop_->Run();
35 }
36
37 private:
38 void QuitNestedRunLoop() {
39 if (run_loop_) {
40 run_loop_->Quit();
41 }
42 }
43
44 // Overridden from ApplicationDelegate:
45 void Initialize(mojo::ApplicationImpl* app) override {
46 ViewManagerTestBase::Initialize(app);
47 app_ = app;
48 }
49
50 // Overridden from ViewTreeDelegate:
51 void OnEmbed(mojo::View* root) override {
52 root_ = root;
sky 2015/09/10 22:09:30 You don't really need to cache this. The only reas
53 content_ = root_->connection()->CreateView();
54 root_->AddChild(content_);
55 content_->SetVisible(true);
56
57 web_view_.Init(app_, content_);
58
59 ViewManagerTestBase::OnEmbed(root);
60 }
61
62 void TearDown() override {
63 mojo::ScopedViewPtr::DeleteViewOrViewManager(root_);
sky 2015/09/10 22:09:30 I think this should move to ViewManagerTestBase. B
64 ViewManagerTestBase::TearDown();
65 }
66
67 // Overridden from web_view::mojom::WebViewClient:
68 void TopLevelNavigate(mojo::URLRequestPtr request) override {}
69 void LoadingStateChanged(bool is_loading) override {
70 if (is_loading == false)
71 QuitNestedRunLoop();
72 }
73 void ProgressChanged(double progress) override {}
74 void TitleChanged(const mojo::String& title) override {
75 last_title_ = title.get();
76 }
77
78 mojo::ApplicationImpl* app_;
79
80 mojo::View* root_;
81 mojo::View* content_;
82
83 web_view::WebView web_view_;
84
85 scoped_ptr<base::RunLoop> run_loop_;
86
87 std::string last_title_;
88
89 DISALLOW_COPY_AND_ASSIGN(WebViewTest);
90 };
91
92 TEST_F(WebViewTest, TestTitleChanged) {
93 base::FilePath data_file;
94 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_file));
95 data_file = data_file.AppendASCII("components").AppendASCII("web_view").
96 AppendASCII("test").AppendASCII("data").
97 AppendASCII("test_title_changed.html");
98 ASSERT_TRUE(base::PathExists(data_file));
99
100 mojo::URLRequestPtr request(mojo::URLRequest::New());
101 request->url = mojo::util::FilePathToFileURL(data_file).spec();
102 web_view()->LoadRequest(request.Pass());
103
104 // Build a nested run loop.
105 StartNestedRunLoopUntilLoadingDone();
106
107 // Our title should have been set on the final.
108 EXPECT_EQ(last_title(), "Test Title Changed");
109 }
110
111 } // namespace web_view
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698