Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/extensions/api/feedback_private/feedback_browsertest.cc

Issue 2934303002: Provide a better way of injecting extra diagnostics in feedbacks (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
93 "" /* extra_diagnostics */);
Peter Kasting 2017/06/14 20:41:04 Nit: Use std::string() in place of "" everywhere
afakhry 2017/06/14 22:10:18 Done.
90 VerifyFeedbackAppLaunch(); 94 VerifyFeedbackAppLaunch();
91 } 95 }
92 96
93 IN_PROC_BROWSER_TEST_F(FeedbackTest, ShowLoginFeedback) { 97 IN_PROC_BROWSER_TEST_F(FeedbackTest, ShowLoginFeedback) {
94 WaitForExtensionViewsToLoad(); 98 WaitForExtensionViewsToLoad();
95 99
96 ASSERT_TRUE(IsFeedbackAppAvailable()); 100 ASSERT_TRUE(IsFeedbackAppAvailable());
97 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_LOGIN); 101 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_LOGIN,
102 "" /* extra_diagnostics */);
98 VerifyFeedbackAppLaunch(); 103 VerifyFeedbackAppLaunch();
99 104
100 AppWindow* const window = 105 AppWindow* const window =
101 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); 106 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser());
102 ASSERT_TRUE(window); 107 ASSERT_TRUE(window);
103 content::WebContents* const content = window->web_contents(); 108 content::WebContents* const content = window->web_contents();
104 109
105 bool bool_result = false; 110 bool bool_result = false;
106 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 111 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
107 content, 112 content,
108 "domAutomationController.send(" 113 "domAutomationController.send("
109 "$('page-url').hidden && $('attach-file-container').hidden && " 114 "$('page-url').hidden && $('attach-file-container').hidden && "
110 "$('attach-file-note').hidden);", 115 "$('attach-file-note').hidden);",
111 &bool_result)); 116 &bool_result));
112 EXPECT_TRUE(bool_result); 117 EXPECT_TRUE(bool_result);
113 } 118 }
114 119
115 // Tests that there's an option in the email drop down box with a value 120 // Tests that there's an option in the email drop down box with a value
116 // 'anonymous_user'. 121 // 'anonymous_user'.
117 IN_PROC_BROWSER_TEST_F(FeedbackTest, AnonymousUser) { 122 IN_PROC_BROWSER_TEST_F(FeedbackTest, AnonymousUser) {
118 WaitForExtensionViewsToLoad(); 123 WaitForExtensionViewsToLoad();
119 124
120 ASSERT_TRUE(IsFeedbackAppAvailable()); 125 ASSERT_TRUE(IsFeedbackAppAvailable());
121 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_REGULAR); 126 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_REGULAR,
127 "" /* extra_diagnostics */);
122 VerifyFeedbackAppLaunch(); 128 VerifyFeedbackAppLaunch();
123 129
124 AppWindow* const window = 130 AppWindow* const window =
125 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser()); 131 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser());
126 ASSERT_TRUE(window); 132 ASSERT_TRUE(window);
127 content::WebContents* const content = window->web_contents(); 133 content::WebContents* const content = window->web_contents();
128 134
129 bool bool_result = false; 135 bool bool_result = false;
130 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 136 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
131 content, 137 content,
132 "domAutomationController.send(" 138 "domAutomationController.send("
133 " ((function() {" 139 " ((function() {"
134 " var options = $('user-email-drop-down').options;" 140 " var options = $('user-email-drop-down').options;"
135 " for (var option in options) {" 141 " for (var option in options) {"
136 " if (options[option].value == 'anonymous_user')" 142 " if (options[option].value == 'anonymous_user')"
137 " return true;" 143 " return true;"
138 " }" 144 " }"
139 " return false;" 145 " return false;"
140 " })()));", 146 " })()));",
141 &bool_result)); 147 &bool_result));
142 148
143 EXPECT_TRUE(bool_result); 149 EXPECT_TRUE(bool_result);
144 } 150 }
145 151
152 // Makes sure that for feedbacks requested given extra diagnostics, the
Peter Kasting 2017/06/14 20:41:04 Nit: Grammar; how about "Ensures that when extra d
afakhry 2017/06/14 22:10:18 Done.
153 // diagnostics are injected properly in the system information.
154 IN_PROC_BROWSER_TEST_F(FeedbackTest, ExtraDiagnostics) {
155 WaitForExtensionViewsToLoad();
156
157 ASSERT_TRUE(IsFeedbackAppAvailable());
158 StartFeedbackUI(FeedbackFlow::FEEDBACK_FLOW_REGULAR, "Some diagnostics");
159 VerifyFeedbackAppLaunch();
160
161 AppWindow* const window =
162 PlatformAppBrowserTest::GetFirstAppWindowForBrowser(browser());
163 ASSERT_TRUE(window);
164 content::WebContents* const content = window->web_contents();
165
166 bool bool_result = false;
167 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
168 content,
169 "domAutomationController.send("
170 " ((function() {"
171 " var sysInfo = feedbackInfo.systemInformation;"
172 " for (var info in sysInfo) {"
173 " if (sysInfo[info].key == 'EXTRA_DIAGNOSTICS' &&"
174 " sysInfo[info].value == 'Some diagnostics') {"
175 " return true;"
176 " }"
177 " }"
178 " return false;"
179 " })()));",
180 &bool_result));
181
182 EXPECT_TRUE(bool_result);
183 }
184
146 } // namespace extensions 185 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698