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

Unified Diff: chrome/browser/apps/app_view_browsertest.cc

Issue 354483004: Implement <appview> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@app_view_skeleton
Patch Set: Added tests Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/apps/app_view_browsertest.cc
diff --git a/chrome/browser/apps/app_view_browsertest.cc b/chrome/browser/apps/app_view_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..44b0b0df4027b227eefe1f6a01621d43af304d0a
--- /dev/null
+++ b/chrome/browser/apps/app_view_browsertest.cc
@@ -0,0 +1,150 @@
+// Copyright 2014 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 "base/strings/stringprintf.h"
+#include "chrome/browser/apps/app_browsertest_util.h"
+#include "chrome/browser/extensions/extension_test_message_listener.h"
+#include "chrome/browser/guest_view/guest_view_manager.h"
+#include "chrome/browser/guest_view/guest_view_manager_factory.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_utils.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/test/embedded_test_server/http_request.h"
+#include "net/test/embedded_test_server/http_response.h"
+
+namespace {
+
+class TestGuestViewManager : public GuestViewManager {
+ public:
+ explicit TestGuestViewManager(content::BrowserContext* context) :
+ GuestViewManager(context),
+ web_contents_(NULL) {}
+
+ content::WebContents* WaitForGuestCreated() {
+ if (web_contents_)
+ return web_contents_;
+
+ message_loop_runner_ = new content::MessageLoopRunner;
+ message_loop_runner_->Run();
+ return web_contents_;
+ }
+
+ private:
+ // GuestViewManager override:
+ virtual void AddGuest(int guest_instance_id,
+ content::WebContents* guest_web_contents) OVERRIDE{
+ GuestViewManager::AddGuest(guest_instance_id, guest_web_contents);
+ web_contents_ = guest_web_contents;
+
+ if (message_loop_runner_)
+ message_loop_runner_->Quit();
+ }
+
+ content::WebContents* web_contents_;
+ scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
+};
+
+// Test factory for creating test instances of GuestViewManager.
+class TestGuestViewManagerFactory : public GuestViewManagerFactory {
+ public:
+ TestGuestViewManagerFactory() :
+ test_guest_view_manager_(NULL) {}
+
+ virtual ~TestGuestViewManagerFactory() {}
+
+ virtual GuestViewManager* CreateGuestViewManager(
+ content::BrowserContext* context) OVERRIDE {
+ return GetManager(context);
+ }
+
+ TestGuestViewManager* GetManager(content::BrowserContext* context) {
+ if (!test_guest_view_manager_) {
+ test_guest_view_manager_ = new TestGuestViewManager(context);
+ }
+ return test_guest_view_manager_;
+ }
+
+ private:
+ TestGuestViewManager* test_guest_view_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory);
+};
+
+} // namespace
+
+class AppViewTest : public extensions::PlatformAppBrowserTest {
+ public:
+ AppViewTest() {
+ GuestViewManager::set_factory_for_testing(&factory_);
+ }
+
+ TestGuestViewManager* GetGuestViewManager() {
+ return factory_.GetManager(browser()->profile());
+ }
+
+ enum TestServer {
+ NEEDS_TEST_SERVER,
+ NO_TEST_SERVER
+ };
+
+ void TestHelper(const std::string& test_name,
+ const std::string& app_location,
+ const std::string& app_to_embed,
+ TestServer test_server) {
+ // For serving guest pages.
+ if (test_server == NEEDS_TEST_SERVER) {
+ if (!StartEmbeddedTestServer()) {
+ LOG(ERROR) << "FAILED TO START TEST SERVER.";
+ return;
+ }
+ }
+
+ LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
+
+ // Flush any pending events to make sure we start with a clean slate.
+ content::RunAllPendingInMessageLoop();
+
+ content::WebContents* embedder_web_contents =
+ GetFirstAppWindowWebContents();
+ if (!embedder_web_contents) {
+ LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
+ return;
+ }
+
+ ExtensionTestMessageListener done_listener("TEST_PASSED", false);
+ done_listener.set_failure_message("TEST_FAILED");
+ if (!content::ExecuteScript(
+ embedder_web_contents,
+ base::StringPrintf("runTest('%s', '%s')",
+ test_name.c_str(),
+ app_to_embed.c_str()))) {
+ LOG(ERROR) << "UNABLE TO START TEST.";
+ return;
+ }
+ ASSERT_TRUE(done_listener.WaitUntilSatisfied());
+ }
+
+ private:
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ command_line->AppendSwitch(switches::kEnableAppView);
+ extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
+ }
+
+ TestGuestViewManagerFactory factory_;
+};
+
+// Tests that <appview> is able to navigate to another installed app.
+IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewBasic) {
+ const extensions::Extension* skeleton_app =
+ InstallPlatformApp("app_view/shim/skeleton");
+ TestHelper("testAppViewBasic",
+ "app_view/shim",
+ skeleton_app->id(),
+ NO_TEST_SERVER);
+}
+
« no previous file with comments | « no previous file | chrome/browser/apps/web_view_browsertest.cc » ('j') | chrome/browser/apps/web_view_browsertest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698