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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 #include "chrome/browser/engagement/site_engagement_service.h" 6 #include "chrome/browser/engagement/site_engagement_service.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" 8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 9 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 59 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
60 browser()->tab_strip_model()->GetActiveWebContents(), 60 browser()->tab_strip_model()->GetActiveWebContents(),
61 "window.whenPageIsPopulatedForTest().then(() => {" 61 "window.whenPageIsPopulatedForTest().then(() => {"
62 " window.domAutomationController.send(true);" 62 " window.domAutomationController.send(true);"
63 "});", 63 "});",
64 &page_is_populated_)); 64 &page_is_populated_));
65 65
66 ASSERT_TRUE(page_is_populated_); 66 ASSERT_TRUE(page_is_populated_);
67 } 67 }
68 68
69 // Verifies that a row exists for the specified site URL. 69 // Expects that there will be the specified number of rows.
70 void ExpectPageContainsUrl(const GURL& url) { 70 int NumberOfRows() {
71 ASSERT_TRUE(page_is_populated_); 71 EXPECT_TRUE(page_is_populated_);
72 72
73 bool found_url = false; 73 int number_of_rows = -1;
74 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 74 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
75 browser()->tab_strip_model()->GetActiveWebContents(), 75 browser()->tab_strip_model()->GetActiveWebContents(),
76 base::JoinString( 76 "window.domAutomationController.send("
77 {"var origin_cells = " 77 " document.getElementsByClassName('origin-cell').length);",
78 " Array.from(document.getElementsByClassName('origin-cell'));" 78 &number_of_rows));
79 "window.domAutomationController.send(origin_cells.reduce(" 79
80 " (found, element) => {" 80 return number_of_rows;
81 " return found || (element.innerHTML == '", 81 }
82 url.spec(), 82
83 "');" 83 // Returns the origin URL at the specified zero-based row index.
84 " }, false));"}, 84 std::string OriginUrlAtRow(int index) {
85 ""), 85 EXPECT_TRUE(page_is_populated_);
86 &found_url)); 86
87 EXPECT_TRUE(found_url); 87 std::string origin_url;
88 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
89 browser()->tab_strip_model()->GetActiveWebContents(),
90 base::JoinString({"window.domAutomationController.send("
91 " document.getElementsByClassName('origin-cell')[",
92 base::IntToString(index), "].innerHTML);"},
93 ""),
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 :-/
94 &origin_url));
95
96 return origin_url;
97 }
98
99 // Returns the stringified score at the specified zero-based row index.
100 std::string ScoreAtRow(int index) {
101 EXPECT_TRUE(page_is_populated_);
102
103 std::string score_string;
104 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
105 browser()->tab_strip_model()->GetActiveWebContents(),
106 base::JoinString({"window.domAutomationController.send("
107 " document.getElementsByClassName('score-input')[",
108 base::IntToString(index), "].value);"},
109 ""),
110 &score_string));
111
112 return score_string;
88 } 113 }
89 114
90 private: 115 private:
91 // True if the page contains site engagement data. 116 // True if the page contains site engagement data.
92 bool page_is_populated_ = false; 117 bool page_is_populated_ = false;
93 }; 118 };
94 119
95 IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest, Basic) { 120 IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest, Basic) {
96 ResetBaseScoreToMax(kExampleUrl); 121 ResetBaseScoreToMax(kExampleUrl);
97 122
98 NavigateToWebUi(); 123 NavigateToWebUi();
99 WaitUntilPagePopulated(); 124 WaitUntilPagePopulated();
100 125
101 ExpectPageContainsUrl(kExampleUrl); 126 EXPECT_EQ(1, NumberOfRows());
127 EXPECT_EQ(kExampleUrl, OriginUrlAtRow(0));
102 } 128 }
129
130 IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest,
131 ScoresHaveTwoDecimalPlaces) {
132 ResetBaseScore(kExampleUrl, 3.14159);
133
134 NavigateToWebUi();
135 WaitUntilPagePopulated();
136
137 EXPECT_EQ(1, NumberOfRows());
138 EXPECT_EQ("3.14", ScoreAtRow(0));
139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698