Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / feedback_private / feedback_browsertest.cc
blobb166f4cdb0e96a4e6e84f57a73d339a74c4821d9
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 "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 "content/public/common/content_switches.h"
16 #include "content/public/test/test_utils.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"
22 namespace {
24 void StopMessageLoopCallback() {
25 base::MessageLoopForUI::current()->Quit();
28 } // namespace
30 namespace extensions {
32 class FeedbackTest : public ExtensionBrowserTest {
33 public:
34 void SetUp() override {
35 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
36 InProcessBrowserTest::SetUp();
39 void SetUpCommandLine(base::CommandLine* command_line) override {
40 command_line->AppendSwitch(::switches::kEnableUserMediaScreenCapturing);
41 InProcessBrowserTest::SetUpCommandLine(command_line);
44 protected:
45 bool IsFeedbackAppAvailable() {
46 return extensions::EventRouter::Get(browser()->profile())
47 ->ExtensionHasEventListener(
48 kFeedbackExtensionId,
49 extensions::api::feedback_private::OnFeedbackRequested::kEventName);
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);
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));
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"));
80 // See http://crbug.com/369886.
81 IN_PROC_BROWSER_TEST_F(FeedbackTest, DISABLED_ShowFeedback) {
82 WaitForExtensionViewsToLoad();
84 ASSERT_TRUE(IsFeedbackAppAvailable());
85 StartFeedbackUI();
86 VerifyFeedbackAppLaunch();
89 } // namespace extensions