feedback_browsertest.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 "apps/app_window.h" 6#include "apps/app_window_registry.h" 7#include "base/bind.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" 21 22using apps::AppWindow; 23using apps::AppWindowRegistry; 24using extensions::Extension; 25 26namespace { 27 28void StopMessageLoopCallback() { 29 base::MessageLoopForUI::current()->Quit(); 30} 31 32} // namespace 33 34namespace extensions { 35 36class FeedbackTest : public ExtensionBrowserTest { 37 public: 38 virtual void SetUp() OVERRIDE { 39 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); 40 InProcessBrowserTest::SetUp(); 41 } 42 43 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 44 command_line->AppendSwitch(::switches::kEnableUserMediaScreenCapturing); 45 InProcessBrowserTest::SetUpCommandLine(command_line); 46 } 47 48 protected: 49 bool IsFeedbackAppAvailable() { 50 return extensions::ExtensionSystem::Get( 51 browser()->profile())->event_router()->ExtensionHasEventListener( 52 kFeedbackExtensionId, 53 extensions::api::feedback_private::OnFeedbackRequested::kEventName); 54 } 55 56 void StartFeedbackUI() { 57 base::Closure callback = base::Bind(&StopMessageLoopCallback); 58 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(&callback); 59 InvokeFeedbackUI(); 60 content::RunMessageLoop(); 61 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(NULL); 62 } 63 64 void VerifyFeedbackAppLaunch() { 65 AppWindow* window = 66 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); 67 ASSERT_TRUE(window); 68 const Extension* feedback_app = window->extension(); 69 ASSERT_TRUE(feedback_app); 70 EXPECT_EQ(feedback_app->id(), std::string(kFeedbackExtensionId)); 71 } 72 73 private: 74 void InvokeFeedbackUI() { 75 extensions::FeedbackPrivateAPI* api = 76 extensions::FeedbackPrivateAPI::GetFactoryInstance()->GetForProfile( 77 browser()->profile()); 78 api->RequestFeedback("Test description", 79 "Test tag", 80 GURL("http://www.test.com")); 81 } 82}; 83 84IN_PROC_BROWSER_TEST_F(FeedbackTest, ShowFeedback) { 85 WaitForExtensionViewsToLoad(); 86 87 ASSERT_TRUE(IsFeedbackAppAvailable()); 88 StartFeedbackUI(); 89 VerifyFeedbackAppLaunch(); 90} 91 92} // namespace extensions 93