| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "chrome/browser/apps/app_browsertest_util.h" | 7 #include "chrome/browser/apps/app_browsertest_util.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h" | 9 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h" |
| 10 #include "chrome/browser/extensions/component_loader.h" | 10 #include "chrome/browser/extensions/component_loader.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 protected: | 49 protected: |
| 50 bool IsFeedbackAppAvailable() { | 50 bool IsFeedbackAppAvailable() { |
| 51 return extensions::EventRouter::Get(browser()->profile()) | 51 return extensions::EventRouter::Get(browser()->profile()) |
| 52 ->ExtensionHasEventListener( | 52 ->ExtensionHasEventListener( |
| 53 extension_misc::kFeedbackExtensionId, | 53 extension_misc::kFeedbackExtensionId, |
| 54 extensions::api::feedback_private::OnFeedbackRequested::kEventName); | 54 extensions::api::feedback_private::OnFeedbackRequested::kEventName); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void StartFeedbackUI(FeedbackFlow flow) { | 57 void StartFeedbackUI(FeedbackFlow flow, |
| 58 const std::string& extra_diagnostics) { |
| 58 base::Closure callback = base::Bind(&StopMessageLoopCallback); | 59 base::Closure callback = base::Bind(&StopMessageLoopCallback); |
| 59 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(&callback); | 60 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(&callback); |
| 60 InvokeFeedbackUI(flow); | 61 InvokeFeedbackUI(flow, extra_diagnostics); |
| 61 content::RunMessageLoop(); | 62 content::RunMessageLoop(); |
| 62 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(NULL); | 63 extensions::FeedbackPrivateGetStringsFunction::set_test_callback(NULL); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void VerifyFeedbackAppLaunch() { | 66 void VerifyFeedbackAppLaunch() { |
| 66 AppWindow* window = | 67 AppWindow* window = |
| 67 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); | 68 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); |
| 68 ASSERT_TRUE(window); | 69 ASSERT_TRUE(window); |
| 69 const Extension* feedback_app = window->GetExtension(); | 70 const Extension* feedback_app = window->GetExtension(); |
| 70 ASSERT_TRUE(feedback_app); | 71 ASSERT_TRUE(feedback_app); |
| 71 EXPECT_EQ(feedback_app->id(), | 72 EXPECT_EQ(feedback_app->id(), |
| 72 std::string(extension_misc::kFeedbackExtensionId)); | 73 std::string(extension_misc::kFeedbackExtensionId)); |
| 73 } | 74 } |
| 74 | 75 |
| 75 private: | 76 private: |
| 76 void InvokeFeedbackUI(FeedbackFlow flow) { | 77 void InvokeFeedbackUI(FeedbackFlow flow, |
| 78 const std::string& extra_diagnostics) { |
| 77 extensions::FeedbackPrivateAPI* api = | 79 extensions::FeedbackPrivateAPI* api = |
| 78 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get( | 80 extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get( |
| 79 browser()->profile()); | 81 browser()->profile()); |
| 80 api->RequestFeedbackForFlow("Test description", "Test tag", | 82 api->RequestFeedbackForFlow("Test description", "Test tag", |
| 81 GURL("http://www.test.com"), flow); | 83 extra_diagnostics, GURL("http://www.test.com"), |
| 84 flow); |
| 82 } | 85 } |
| 83 }; | 86 }; |
| 84 | 87 |
| 85 IN_PROC_BROWSER_TEST_F(FeedbackTest, ShowFeedback) { | 88 IN_PROC_BROWSER_TEST_F(FeedbackTest, ShowFeedback) { |
| 86 WaitForExtensionViewsToLoad(); | 89 WaitForExtensionViewsToLoad(); |
| 87 | 90 |
| 88 ASSERT_TRUE(IsFeedbackAppAvailable()); | 91 ASSERT_TRUE(IsFeedbackAppAvailable()); |
| 89 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_REGULAR); | 92 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_REGULAR, std::string()); |
| 90 VerifyFeedbackAppLaunch(); | 93 VerifyFeedbackAppLaunch(); |
| 91 } | 94 } |
| 92 | 95 |
| 93 IN_PROC_BROWSER_TEST_F(FeedbackTest, ShowLoginFeedback) { | 96 IN_PROC_BROWSER_TEST_F(FeedbackTest, ShowLoginFeedback) { |
| 94 WaitForExtensionViewsToLoad(); | 97 WaitForExtensionViewsToLoad(); |
| 95 | 98 |
| 96 ASSERT_TRUE(IsFeedbackAppAvailable()); | 99 ASSERT_TRUE(IsFeedbackAppAvailable()); |
| 97 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_LOGIN); | 100 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_LOGIN, std::string()); |
| 98 VerifyFeedbackAppLaunch(); | 101 VerifyFeedbackAppLaunch(); |
| 99 | 102 |
| 100 AppWindow* const window = | 103 AppWindow* const window = |
| 101 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); | 104 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); |
| 102 ASSERT_TRUE(window); | 105 ASSERT_TRUE(window); |
| 103 content::WebContents* const content = window->web_contents(); | 106 content::WebContents* const content = window->web_contents(); |
| 104 | 107 |
| 105 bool bool_result = false; | 108 bool bool_result = false; |
| 106 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 109 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 107 content, | 110 content, |
| 108 "domAutomationController.send(" | 111 "domAutomationController.send(" |
| 109 "$('page-url').hidden && $('attach-file-container').hidden && " | 112 "$('page-url').hidden && $('attach-file-container').hidden && " |
| 110 "$('attach-file-note').hidden);", | 113 "$('attach-file-note').hidden);", |
| 111 &bool_result)); | 114 &bool_result)); |
| 112 EXPECT_TRUE(bool_result); | 115 EXPECT_TRUE(bool_result); |
| 113 } | 116 } |
| 114 | 117 |
| 115 // Tests that there's an option in the email drop down box with a value | 118 // Tests that there's an option in the email drop down box with a value |
| 116 // 'anonymous_user'. | 119 // 'anonymous_user'. |
| 117 IN_PROC_BROWSER_TEST_F(FeedbackTest, AnonymousUser) { | 120 IN_PROC_BROWSER_TEST_F(FeedbackTest, AnonymousUser) { |
| 118 WaitForExtensionViewsToLoad(); | 121 WaitForExtensionViewsToLoad(); |
| 119 | 122 |
| 120 ASSERT_TRUE(IsFeedbackAppAvailable()); | 123 ASSERT_TRUE(IsFeedbackAppAvailable()); |
| 121 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_REGULAR); | 124 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_REGULAR, std::string()); |
| 122 VerifyFeedbackAppLaunch(); | 125 VerifyFeedbackAppLaunch(); |
| 123 | 126 |
| 124 AppWindow* const window = | 127 AppWindow* const window = |
| 125 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); | 128 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); |
| 126 ASSERT_TRUE(window); | 129 ASSERT_TRUE(window); |
| 127 content::WebContents* const content = window->web_contents(); | 130 content::WebContents* const content = window->web_contents(); |
| 128 | 131 |
| 129 bool bool_result = false; | 132 bool bool_result = false; |
| 130 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 133 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 131 content, | 134 content, |
| 132 "domAutomationController.send(" | 135 "domAutomationController.send(" |
| 133 " ((function() {" | 136 " ((function() {" |
| 134 " var options = $('user-email-drop-down').options;" | 137 " var options = $('user-email-drop-down').options;" |
| 135 " for (var option in options) {" | 138 " for (var option in options) {" |
| 136 " if (options[option].value == 'anonymous_user')" | 139 " if (options[option].value == 'anonymous_user')" |
| 137 " return true;" | 140 " return true;" |
| 138 " }" | 141 " }" |
| 139 " return false;" | 142 " return false;" |
| 140 " })()));", | 143 " })()));", |
| 141 &bool_result)); | 144 &bool_result)); |
| 142 | 145 |
| 143 EXPECT_TRUE(bool_result); | 146 EXPECT_TRUE(bool_result); |
| 144 } | 147 } |
| 145 | 148 |
| 149 // Ensures that when extra diagnostics are provided with feedback, they are |
| 150 // injected properly in the system information. |
| 151 IN_PROC_BROWSER_TEST_F(FeedbackTest, ExtraDiagnostics) { |
| 152 WaitForExtensionViewsToLoad(); |
| 153 |
| 154 ASSERT_TRUE(IsFeedbackAppAvailable()); |
| 155 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_REGULAR, "Some diagnostics"); |
| 156 VerifyFeedbackAppLaunch(); |
| 157 |
| 158 AppWindow* const window = |
| 159 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); |
| 160 ASSERT_TRUE(window); |
| 161 content::WebContents* const content = window->web_contents(); |
| 162 |
| 163 bool bool_result = false; |
| 164 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 165 content, |
| 166 "domAutomationController.send(" |
| 167 " ((function() {" |
| 168 " var sysInfo = feedbackInfo.systemInformation;" |
| 169 " for (var info in sysInfo) {" |
| 170 " if (sysInfo[info].key == 'EXTRA_DIAGNOSTICS' &&" |
| 171 " sysInfo[info].value == 'Some diagnostics') {" |
| 172 " return true;" |
| 173 " }" |
| 174 " }" |
| 175 " return false;" |
| 176 " })()));", |
| 177 &bool_result)); |
| 178 |
| 179 EXPECT_TRUE(bool_result); |
| 180 } |
| 181 |
| 146 } // namespace extensions | 182 } // namespace extensions |
| OLD | NEW |