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

Unified Diff: chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc

Issue 2788413003: Add SiteEngagementService::GetAllDetails(), to return detailed scores. (Closed)
Patch Set: Fix notifications permission logic & test Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc
diff --git a/chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc b/chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc
index b1d442e24a6e28a08ec488f8e3a88e53e12fac8d..7a437bdf3c24f87a946a32249a64d06dd4dd7f85 100644
--- a/chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc
@@ -66,25 +66,50 @@ class SiteEngagementUiBrowserTest : public InProcessBrowserTest {
ASSERT_TRUE(page_is_populated_);
}
- // Verifies that a row exists for the specified site URL.
- void ExpectPageContainsUrl(const GURL& url) {
- ASSERT_TRUE(page_is_populated_);
+ // Expects that there will be the specified number of rows.
+ int NumberOfRows() {
+ EXPECT_TRUE(page_is_populated_);
- bool found_url = false;
- ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ int number_of_rows = -1;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
+ browser()->tab_strip_model()->GetActiveWebContents(),
+ "window.domAutomationController.send("
+ " document.getElementsByClassName('origin-cell').length);",
+ &number_of_rows));
+
+ return number_of_rows;
+ }
+
+ // Returns the origin URL at the specified zero-based row index.
+ std::string OriginUrlAtRow(int index) {
+ EXPECT_TRUE(page_is_populated_);
+
+ std::string origin_url;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
browser()->tab_strip_model()->GetActiveWebContents(),
- base::JoinString(
- {"var origin_cells = "
- " Array.from(document.getElementsByClassName('origin-cell'));"
- "window.domAutomationController.send(origin_cells.reduce("
- " (found, element) => {"
- " return found || (element.innerHTML == '",
- url.spec(),
- "');"
- " }, false));"},
- ""),
- &found_url));
- EXPECT_TRUE(found_url);
+ base::JoinString({"window.domAutomationController.send("
+ " document.getElementsByClassName('origin-cell')[",
+ base::IntToString(index), "].innerHTML);"},
+ ""),
Dan Beam 2017/04/11 15:57:48 can you `git cl format` this? is it already?
Wez 2017/04/11 19:57:07 Yes, this is already git cl formatted :-/
+ &origin_url));
+
+ return origin_url;
+ }
+
+ // Returns the stringified score at the specified zero-based row index.
+ std::string ScoreAtRow(int index) {
+ EXPECT_TRUE(page_is_populated_);
+
+ std::string score_string;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
+ browser()->tab_strip_model()->GetActiveWebContents(),
+ base::JoinString({"window.domAutomationController.send("
+ " document.getElementsByClassName('score-input')[",
+ base::IntToString(index), "].value);"},
+ ""),
+ &score_string));
+
+ return score_string;
}
private:
@@ -98,5 +123,17 @@ IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest, Basic) {
NavigateToWebUi();
WaitUntilPagePopulated();
- ExpectPageContainsUrl(kExampleUrl);
+ EXPECT_EQ(1, NumberOfRows());
+ EXPECT_EQ(kExampleUrl, OriginUrlAtRow(0));
+}
+
+IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest,
+ ScoresHaveTwoDecimalPlaces) {
+ ResetBaseScore(kExampleUrl, 3.14159);
+
+ NavigateToWebUi();
+ WaitUntilPagePopulated();
+
+ EXPECT_EQ(1, NumberOfRows());
+ EXPECT_EQ("3.14", ScoreAtRow(0));
}

Powered by Google App Engine
This is Rietveld 408576698