Chromium Code Reviews| Index: extensions/browser/guest_view/app_view/app_view_apitest.cc |
| diff --git a/extensions/browser/guest_view/app_view/app_view_apitest.cc b/extensions/browser/guest_view/app_view/app_view_apitest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cb8585b6c4248789df1ea7f7dd7ac5017d819eca |
| --- /dev/null |
| +++ b/extensions/browser/guest_view/app_view/app_view_apitest.cc |
| @@ -0,0 +1,109 @@ |
| +// 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/path_service.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "content/public/test/browser_test.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "extensions/browser/app_window/app_window.h" |
| +#include "extensions/browser/app_window/app_window_registry.h" |
| +#include "extensions/browser/guest_view/guest_view_manager.h" |
| +#include "extensions/browser/guest_view/guest_view_manager_factory.h" |
| +#include "extensions/browser/guest_view/test_guest_view_manager.h" |
| +#include "extensions/common/extension.h" |
| +#include "extensions/common/extension_paths.h" |
| +#include "extensions/shell/browser/shell_content_browser_client.h" |
| +#include "extensions/shell/browser/shell_extension_system.h" |
| +#include "extensions/shell/test/shell_test.h" |
| +#include "extensions/test/extension_test_message_listener.h" |
| +#include "net/base/filename_util.h" |
| + |
| +namespace extensions { |
| + |
| +class AppViewTest : public AppShellTest { |
| + protected: |
| + AppViewTest() { |
| + extensions::GuestViewManager::set_factory_for_testing(&factory_); |
|
Yoyo Zhou
2014/10/29 20:37:58
nit: don't need extensions::
lfg
2014/10/30 23:38:16
Done.
|
| + } |
| + |
| + TestGuestViewManager* GetGuestViewManager() { |
| + return static_cast<TestGuestViewManager*>( |
| + TestGuestViewManager::FromBrowserContext( |
| + ShellContentBrowserClient::Get()->GetBrowserContext())); |
| + } |
| + |
| + content::WebContents* GetFirstAppWindowWebContents() { |
| + const AppWindowRegistry::AppWindowList& app_window_list = |
| + AppWindowRegistry::Get(browser_context_)->app_windows(); |
| + DCHECK(app_window_list.size() == 1); |
| + return (*app_window_list.begin())->web_contents(); |
| + } |
| + |
| + const Extension* LoadApp(const std::string& app_location) { |
| + base::FilePath test_data_dir; |
| + PathService::Get(DIR_TEST_DATA, &test_data_dir); |
| + test_data_dir = test_data_dir.AppendASCII(app_location.c_str()); |
| + return extension_system_->LoadApp(test_data_dir); |
| + } |
| + |
| + void RunTest(const std::string& test_name, |
| + const std::string& app_location, |
| + const std::string& app_to_embed) { |
| + extension_system_->Init(); |
| + |
| + const Extension* app_embedder = LoadApp(app_location); |
| + ASSERT_TRUE(app_embedder); |
| + const Extension* app_embedded = LoadApp(app_to_embed); |
| + ASSERT_TRUE(app_embedded); |
| + |
| + extension_system_->LaunchApp(app_embedder->id()); |
| + |
| + ExtensionTestMessageListener launch_listener("LAUNCHED", false); |
| + ASSERT_TRUE(launch_listener.WaitUntilSatisfied()); |
| + |
| + embedder_web_contents_ = GetFirstAppWindowWebContents(); |
| + |
| + 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_embedded->id().c_str()))) { |
| + LOG(ERROR) << "Unable to start test."; |
|
Yoyo Zhou
2014/10/29 20:37:58
Does this actually make the test fail? It might be
lfg
2014/10/30 23:38:16
Done. web_view_apitest had the same issue, so I fi
|
| + return; |
| + } |
| + ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| + } |
| + |
| + protected: |
| + content::WebContents* embedder_web_contents_; |
| + TestGuestViewManagerFactory factory_; |
| +}; |
| + |
| +// Tests that <appview> correctly processes parameters passed on connect. |
| +IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewGoodDataShouldSucceed) { |
| + RunTest("testAppViewGoodDataShouldSucceed", |
| + "app_view/apitest", |
| + "app_view/apitest/skeleton"); |
| +} |
| + |
| +// Tests that <appview> correctly processes parameters passed on connect. |
| +// This test should fail to connect because the embedded app (skeleton) will |
| +// refuse the data passed by the embedder app and deny the request. |
| +IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewRefusedDataShouldFail) { |
| + RunTest("testAppViewRefusedDataShouldFail", |
| + "app_view/apitest", |
| + "app_view/apitest/skeleton"); |
| +} |
| + |
| +// Tests that <appview> is able to navigate to another installed app. |
| +IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { |
| + RunTest("testAppViewWithUndefinedDataShouldSucceed", |
| + "app_view/apitest", |
| + "app_view/apitest/skeleton"); |
| +} |
| + |
| +} // namespace extensions |