1 // Copyright 2013 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.
5 #include "apps/app_window.h"
6 #include "apps/app_window_registry.h"
8 #include "chrome/browser/apps/app_browsertest_util.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h"
11 #include "chrome/browser/extensions/component_loader.h"
12 #include "chrome/browser/extensions/extension_browsertest.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/extensions/api/feedback_private.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/common/content_switches.h"
19 #include "extensions/browser/event_router.h"
20 #include "extensions/browser/extension_system.h"
22 using apps::AppWindow;
23 using apps::AppWindowRegistry;
24 using extensions::Extension;
28 void StopMessageLoopCallback() {
29 base::MessageLoopForUI::current()->Quit();
34 namespace extensions {
36 class FeedbackTest : public ExtensionBrowserTest {
38 virtual void SetUp() OVERRIDE {
39 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
40 InProcessBrowserTest::SetUp();
43 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
44 command_line->AppendSwitch(::switches::kEnableUserMediaScreenCapturing);
45 InProcessBrowserTest::SetUpCommandLine(command_line);
49 bool IsFeedbackAppAvailable() {
50 return extensions::ExtensionSystem::Get(
51 browser()->profile())->event_router()->ExtensionHasEventListener(
53 extensions::api::feedback_private::OnFeedbackRequested::kEventName);
56 void StartFeedbackUI() {
57 base::Closure callback = base::Bind(&StopMessageLoopCallback);
58 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(&callback);
60 content::RunMessageLoop();
61 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(NULL);
64 void VerifyFeedbackAppLaunch() {
66 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser());
68 const Extension* feedback_app = window->extension();
69 ASSERT_TRUE(feedback_app);
70 EXPECT_EQ(feedback_app->id(), std::string(kFeedbackExtensionId));
74 void InvokeFeedbackUI() {
75 extensions::FeedbackPrivateAPI* api =
76 extensions::FeedbackPrivateAPI::GetFactoryInstance()->GetForProfile(
77 browser()->profile());
78 api->RequestFeedback("Test description",
80 GURL("http://www.test.com"));
84 IN_PROC_BROWSER_TEST_F(FeedbackTest, ShowFeedback) {
85 WaitForExtensionViewsToLoad();
87 ASSERT_TRUE(IsFeedbackAppAvailable());
89 VerifyFeedbackAppLaunch();
92 } // namespace extensions