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. 4 5 #include "base/bind.h" 6 #include "chrome/browser/apps/app_browsertest_util.h" 7 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h" 9 #include "chrome/browser/extensions/component_loader.h" 10 #include "chrome/browser/extensions/extension_browsertest.h" 11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/common/extensions/api/feedback_private.h" 14 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/ui_test_utils.h" 16 #include "content/public/common/content_switches.h" 17 #include "extensions/browser/app_window/app_window.h" 18 #include "extensions/browser/app_window/app_window_registry.h" 19 #include "extensions/browser/event_router.h" 20 #include "extensions/browser/extension_system.h" 21 22 namespace { 23 24 void StopMessageLoopCallback() { 25 base::MessageLoopForUI::current()->Quit(); 26 } 27 28 } // namespace 29 30 namespace extensions { 31 32 class FeedbackTest : public ExtensionBrowserTest { 33 public: 34 virtual void SetUp() OVERRIDE { 35 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); 36 InProcessBrowserTest::SetUp(); 37 } 38 39 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 40 command_line->AppendSwitch(::switches::kEnableUserMediaScreenCapturing); 41 InProcessBrowserTest::SetUpCommandLine(command_line); 42 } 43 44 protected: 45 bool IsFeedbackAppAvailable() { 46 return extensions::EventRouter::Get(browser()->profile()) 47 ->ExtensionHasEventListener( 48 kFeedbackExtensionId, 49 extensions::api::feedback_private::OnFeedbackRequested::kEventName); 50 } 51 52 void StartFeedbackUI() { 53 base::Closure callback = base::Bind(&StopMessageLoopCallback); 54 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(&callback); 55 InvokeFeedbackUI(); 56 content::RunMessageLoop(); 57 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(NULL); 58 } 59 60 void VerifyFeedbackAppLaunch() { 61 AppWindow* window = 62 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); 63 ASSERT_TRUE(window); 64 const Extension* feedback_app = window->GetExtension(); 65 ASSERT_TRUE(feedback_app); 66 EXPECT_EQ(feedback_app->id(), std::string(kFeedbackExtensionId)); 67 } 68 69 private: 70 void InvokeFeedbackUI() { 71 extensions::FeedbackPrivateAPI* api = 72 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get( 73 browser()->profile()); 74 api->RequestFeedback("Test description", 75 "Test tag", 76 GURL("http://www.test.com")); 77 } 78 }; 79 80 // See http://crbug.com/369886. 81 IN_PROC_BROWSER_TEST_F(FeedbackTest, DISABLED_ShowFeedback) { 82 WaitForExtensionViewsToLoad(); 83 84 ASSERT_TRUE(IsFeedbackAppAvailable()); 85 StartFeedbackUI(); 86 VerifyFeedbackAppLaunch(); 87 } 88 89 } // namespace extensions 90