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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/web_view/web_view_apptest.cc
diff --git a/components/web_view/web_view_apptest.cc b/components/web_view/web_view_apptest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1f19d7171547a43c2dc431e010b89f0a368a61b6
--- /dev/null
+++ b/components/web_view/web_view_apptest.cc
@@ -0,0 +1,111 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/web_view/public/cpp/web_view.h"
+
+#include "base/base_paths.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/run_loop.h"
+#include "components/view_manager/public/cpp/scoped_view_ptr.h"
+#include "components/view_manager/public/cpp/tests/view_manager_test_base.h"
+#include "components/view_manager/public/cpp/view.h"
+#include "components/view_manager/public/cpp/view_tree_connection.h"
+#include "mojo/util/filename_util.h"
+#include "url/gurl.h"
+
+namespace web_view {
+
+class WebViewTest : public mojo::ViewManagerTestBase,
+ public mojom::WebViewClient {
+ public:
+ WebViewTest() : web_view_(this) {}
+ ~WebViewTest() override {}
+
+ mojom::WebView* web_view() { return web_view_.web_view(); }
+
+ const std::string& last_title() { return last_title_; }
+
+ void StartNestedRunLoopUntilLoadingDone() {
+ run_loop_.reset(new base::RunLoop);
+ run_loop_->Run();
+ }
+
+ private:
+ void QuitNestedRunLoop() {
+ if (run_loop_) {
+ run_loop_->Quit();
+ }
+ }
+
+ // Overridden from ApplicationDelegate:
+ void Initialize(mojo::ApplicationImpl* app) override {
+ ViewManagerTestBase::Initialize(app);
+ app_ = app;
+ }
+
+ // Overridden from ViewTreeDelegate:
+ void OnEmbed(mojo::View* root) override {
+ root_ = root;
sky 2015/09/10 22:09:30 You don't really need to cache this. The only reas
+ content_ = root_->connection()->CreateView();
+ root_->AddChild(content_);
+ content_->SetVisible(true);
+
+ web_view_.Init(app_, content_);
+
+ ViewManagerTestBase::OnEmbed(root);
+ }
+
+ void TearDown() override {
+ mojo::ScopedViewPtr::DeleteViewOrViewManager(root_);
sky 2015/09/10 22:09:30 I think this should move to ViewManagerTestBase. B
+ ViewManagerTestBase::TearDown();
+ }
+
+ // Overridden from web_view::mojom::WebViewClient:
+ void TopLevelNavigate(mojo::URLRequestPtr request) override {}
+ void LoadingStateChanged(bool is_loading) override {
+ if (is_loading == false)
+ QuitNestedRunLoop();
+ }
+ void ProgressChanged(double progress) override {}
+ void TitleChanged(const mojo::String& title) override {
+ last_title_ = title.get();
+ }
+
+ mojo::ApplicationImpl* app_;
+
+ mojo::View* root_;
+ mojo::View* content_;
+
+ web_view::WebView web_view_;
+
+ scoped_ptr<base::RunLoop> run_loop_;
+
+ std::string last_title_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebViewTest);
+};
+
+TEST_F(WebViewTest, TestTitleChanged) {
+ base::FilePath data_file;
+ ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_file));
+ data_file = data_file.AppendASCII("components").AppendASCII("web_view").
+ AppendASCII("test").AppendASCII("data").
+ AppendASCII("test_title_changed.html");
+ ASSERT_TRUE(base::PathExists(data_file));
+
+ mojo::URLRequestPtr request(mojo::URLRequest::New());
+ request->url = mojo::util::FilePathToFileURL(data_file).spec();
+ web_view()->LoadRequest(request.Pass());
+
+ // Build a nested run loop.
+ StartNestedRunLoopUntilLoadingDone();
+
+ // Our title should have been set on the final.
+ EXPECT_EQ(last_title(), "Test Title Changed");
+}
+
+} // namespace web_view

Powered by Google App Engine
This is Rietveld 408576698