| OLD | NEW |
| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 browser()->tab_strip_model()->GetActiveWebContents(), | 89 browser()->tab_strip_model()->GetActiveWebContents(), |
| 90 base::JoinString({"window.domAutomationController.send(" | 90 base::JoinString({"window.domAutomationController.send(" |
| 91 " document.getElementsByClassName('origin-cell')[", | 91 " document.getElementsByClassName('origin-cell')[", |
| 92 base::IntToString(index), "].innerHTML);"}, | 92 base::IntToString(index), "].innerHTML);"}, |
| 93 ""), | 93 ""), |
| 94 &origin_url)); | 94 &origin_url)); |
| 95 | 95 |
| 96 return origin_url; | 96 return origin_url; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Returns the stringified score at the specified zero-based row index. | 99 // Returns the stringified base score at the specified zero-based row index. |
| 100 std::string ScoreAtRow(int index) { | 100 std::string BaseScoreAtRow(int index) { |
| 101 EXPECT_TRUE(page_is_populated_); | 101 EXPECT_TRUE(page_is_populated_); |
| 102 | 102 |
| 103 std::string score_string; | 103 std::string score_string; |
| 104 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 104 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 105 browser()->tab_strip_model()->GetActiveWebContents(), | 105 browser()->tab_strip_model()->GetActiveWebContents(), |
| 106 base::JoinString({"window.domAutomationController.send(" | 106 base::JoinString( |
| 107 " document.getElementsByClassName('score-input')[", | 107 {"window.domAutomationController.send(" |
| 108 base::IntToString(index), "].value);"}, | 108 " document.getElementsByClassName('base-score-input')[", |
| 109 ""), | 109 base::IntToString(index), "].value);"}, |
| 110 ""), |
| 110 &score_string)); | 111 &score_string)); |
| 111 | 112 |
| 112 return score_string; | 113 return score_string; |
| 114 } |
| 115 |
| 116 std::string BonusScoreAtRow(int index) { |
| 117 EXPECT_TRUE(page_is_populated_); |
| 118 |
| 119 std::string score_string; |
| 120 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 121 browser()->tab_strip_model()->GetActiveWebContents(), |
| 122 base::JoinString( |
| 123 {"window.domAutomationController.send(" |
| 124 " document.getElementsByClassName('bonus-score-cell')[", |
| 125 base::IntToString(index), "].innerHTML);"}, |
| 126 ""), |
| 127 &score_string)); |
| 128 |
| 129 return score_string; |
| 130 } |
| 131 |
| 132 std::string TotalScoreAtRow(int index) { |
| 133 EXPECT_TRUE(page_is_populated_); |
| 134 |
| 135 std::string score_string; |
| 136 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 137 browser()->tab_strip_model()->GetActiveWebContents(), |
| 138 base::JoinString( |
| 139 {"window.domAutomationController.send(" |
| 140 " document.getElementsByClassName('total-score-cell')[", |
| 141 base::IntToString(index), "].innerHTML);"}, |
| 142 ""), |
| 143 &score_string)); |
| 144 |
| 145 return score_string; |
| 113 } | 146 } |
| 114 | 147 |
| 115 private: | 148 private: |
| 116 // True if the page contains site engagement data. | 149 // True if the page contains site engagement data. |
| 117 bool page_is_populated_ = false; | 150 bool page_is_populated_ = false; |
| 118 }; | 151 }; |
| 119 | 152 |
| 120 IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest, Basic) { | 153 IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest, Basic) { |
| 121 ResetBaseScoreToMax(kExampleUrl); | 154 ResetBaseScoreToMax(kExampleUrl); |
| 122 | 155 |
| 123 NavigateToWebUi(); | 156 NavigateToWebUi(); |
| 124 WaitUntilPagePopulated(); | 157 WaitUntilPagePopulated(); |
| 125 | 158 |
| 126 EXPECT_EQ(1, NumberOfRows()); | 159 EXPECT_EQ(1, NumberOfRows()); |
| 127 EXPECT_EQ(kExampleUrl, OriginUrlAtRow(0)); | 160 EXPECT_EQ(kExampleUrl, OriginUrlAtRow(0)); |
| 128 } | 161 } |
| 129 | 162 |
| 130 IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest, | 163 IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest, |
| 131 ScoresHaveTwoDecimalPlaces) { | 164 ScoresHaveTwoDecimalPlaces) { |
| 132 ResetBaseScore(kExampleUrl, 3.14159); | 165 ResetBaseScore(kExampleUrl, 3.14159); |
| 133 | 166 |
| 134 NavigateToWebUi(); | 167 NavigateToWebUi(); |
| 135 WaitUntilPagePopulated(); | 168 WaitUntilPagePopulated(); |
| 136 | 169 |
| 137 EXPECT_EQ(1, NumberOfRows()); | 170 EXPECT_EQ(1, NumberOfRows()); |
| 138 EXPECT_EQ("3.14", ScoreAtRow(0)); | 171 EXPECT_EQ("3.14", BaseScoreAtRow(0)); |
| 172 EXPECT_EQ("0", BonusScoreAtRow(0)); |
| 173 EXPECT_EQ("3.14", TotalScoreAtRow(0)); |
| 139 } | 174 } |
| OLD | NEW |