| 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 "chrome/browser/history/most_visited_tiles_experiment.h" | 5 #include "chrome/browser/history/most_visited_tiles_experiment.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // The indexes of the tiles that are affected in the experiment. | 39 // The indexes of the tiles that are affected in the experiment. |
| 40 enum FlippedIndexes { | 40 enum FlippedIndexes { |
| 41 TILE_ONE = 0, | 41 TILE_ONE = 0, |
| 42 TILE_FOUR = 3, | 42 TILE_FOUR = 3, |
| 43 TILE_EIGHT = 7 | 43 TILE_EIGHT = 7 |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // Creates a DictionaryValue using |url| and appends to |list|. | 46 // Creates a DictionaryValue using |url| and appends to |list|. |
| 47 void AppendURLToListValue(const std::string& url_string, | 47 void AppendURLToListValue(const std::string& url_string, |
| 48 base::ListValue* list) { | 48 base::ListValue* list) { |
| 49 DictionaryValue* page_value = new DictionaryValue(); | 49 base::DictionaryValue* page_value = new base::DictionaryValue(); |
| 50 page_value->SetString("url", url_string); | 50 page_value->SetString("url", url_string); |
| 51 list->Append(page_value); | 51 list->Append(page_value); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Creates an InstantMostVisitedItem using |url| and appends to |list|. | 54 // Creates an InstantMostVisitedItem using |url| and appends to |list|. |
| 55 void AppendInstantURLToVector(const std::string& url_string, | 55 void AppendInstantURLToVector(const std::string& url_string, |
| 56 std::vector<InstantMostVisitedItem>* list) { | 56 std::vector<InstantMostVisitedItem>* list) { |
| 57 InstantMostVisitedItem item; | 57 InstantMostVisitedItem item; |
| 58 item.url = GURL(url_string); | 58 item.url = GURL(url_string); |
| 59 list->push_back(item); | 59 list->push_back(item); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 std::set<std::string> open_urls; | 154 std::set<std::string> open_urls; |
| 155 open_urls.insert(kGmailURL); | 155 open_urls.insert(kGmailURL); |
| 156 | 156 |
| 157 base::ListValue pages_value; | 157 base::ListValue pages_value; |
| 158 AppendURLToListValue(kGmailURL, &pages_value); | 158 AppendURLToListValue(kGmailURL, &pages_value); |
| 159 | 159 |
| 160 // Test the method when there are not enough URLs to force removal. | 160 // Test the method when there are not enough URLs to force removal. |
| 161 MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs( | 161 MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs( |
| 162 open_urls, &pages_value); | 162 open_urls, &pages_value); |
| 163 DictionaryValue gmail_value; | 163 base::DictionaryValue gmail_value; |
| 164 gmail_value.SetString("url", kGmailURL); | 164 gmail_value.SetString("url", kGmailURL); |
| 165 // Ensure the open url has not been removed from |pages_value|. | 165 // Ensure the open url has not been removed from |pages_value|. |
| 166 EXPECT_NE(pages_value.end(), pages_value.Find(gmail_value)); | 166 EXPECT_NE(pages_value.end(), pages_value.Find(gmail_value)); |
| 167 | 167 |
| 168 // Ensure counts have been incremented correctly. | 168 // Ensure counts have been incremented correctly. |
| 169 EXPECT_NO_FATAL_FAILURE( | 169 EXPECT_NO_FATAL_FAILURE( |
| 170 ValidateMetrics(NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL)); | 170 ValidateMetrics(NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 // For pre-instant extended clients. | 173 // For pre-instant extended clients. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 189 for (size_t i = 0; i < kMinUrlSuggestions; ++i) { | 189 for (size_t i = 0; i < kMinUrlSuggestions; ++i) { |
| 190 std::string url; | 190 std::string url; |
| 191 base::SStringPrintf(&url, "http://www.test%d.com", static_cast<int>(i)); | 191 base::SStringPrintf(&url, "http://www.test%d.com", static_cast<int>(i)); |
| 192 AppendURLToListValue(url, &pages_value); | 192 AppendURLToListValue(url, &pages_value); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Call method with enough URLs to force removal. | 195 // Call method with enough URLs to force removal. |
| 196 MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs( | 196 MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs( |
| 197 open_urls, &pages_value); | 197 open_urls, &pages_value); |
| 198 // Ensure the open url has been removed from |pages_value|. | 198 // Ensure the open url has been removed from |pages_value|. |
| 199 DictionaryValue gmail_value; | 199 base::DictionaryValue gmail_value; |
| 200 gmail_value.SetString("url", kGmailURL); | 200 gmail_value.SetString("url", kGmailURL); |
| 201 EXPECT_EQ(pages_value.end(), pages_value.Find(gmail_value)); | 201 EXPECT_EQ(pages_value.end(), pages_value.Find(gmail_value)); |
| 202 | 202 |
| 203 // Ensure counts have been incremented correctly. | 203 // Ensure counts have been incremented correctly. |
| 204 EXPECT_NO_FATAL_FAILURE( | 204 EXPECT_NO_FATAL_FAILURE( |
| 205 ValidateMetrics(NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL)); | 205 ValidateMetrics(NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL)); |
| 206 } | 206 } |
| 207 | 207 |
| 208 // For instant extended clients. | 208 // For instant extended clients. |
| 209 TEST_F(MostVisitedTilesExperimentTest, RemoveItemsMatchingOpenTabsTooFewURLs) { | 209 TEST_F(MostVisitedTilesExperimentTest, RemoveItemsMatchingOpenTabsTooFewURLs) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 test_urls[TILE_ONE].url.spec()); | 349 test_urls[TILE_ONE].url.spec()); |
| 350 EXPECT_EQ(most_visited_urls[TILE_FOUR-1].url.spec(), | 350 EXPECT_EQ(most_visited_urls[TILE_FOUR-1].url.spec(), |
| 351 test_urls[TILE_FOUR-1].url.spec()); | 351 test_urls[TILE_FOUR-1].url.spec()); |
| 352 | 352 |
| 353 // Ensure counts are correct. | 353 // Ensure counts are correct. |
| 354 EXPECT_NO_FATAL_FAILURE( | 354 EXPECT_NO_FATAL_FAILURE( |
| 355 ValidateMetrics(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_4)); | 355 ValidateMetrics(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_4)); |
| 356 } | 356 } |
| 357 | 357 |
| 358 } // namespace history | 358 } // namespace history |
| OLD | NEW |