OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync/test/integration/search_engines_helper.h" | 5 #include "chrome/browser/sync/test/integration/search_engines_helper.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 CHECK(*it); | 40 CHECK(*it); |
41 CHECK(map.find((*it)->sync_guid()) == map.end()); | 41 CHECK(map.find((*it)->sync_guid()) == map.end()); |
42 map[(*it)->sync_guid()] = *it; | 42 map[(*it)->sync_guid()] = *it; |
43 } | 43 } |
44 | 44 |
45 return map; | 45 return map; |
46 } | 46 } |
47 | 47 |
48 std::string GetTURLInfoString(const TemplateURL* turl) { | 48 std::string GetTURLInfoString(const TemplateURL* turl) { |
49 DCHECK(turl); | 49 DCHECK(turl); |
50 return "TemplateURL: shortname: " + UTF16ToASCII(turl->short_name()) + | 50 std::string shortname = UTF16ToASCII(turl->short_name()); |
51 " keyword: " + UTF16ToASCII(turl->keyword()) + " url: " + turl->url(); | 51 std::string keyword = UTF16ToASCII(turl->keyword()); |
| 52 return StringPrintf("TemplateURL: shortname: %s keyword: %s url: %s", |
| 53 shortname.c_str(), keyword.c_str(), |
| 54 (turl->url() ? turl->url()->url().c_str() : "NULL")); |
52 } | 55 } |
53 | 56 |
54 bool TURLsMatch(const TemplateURL* turl1, const TemplateURL* turl2) { | 57 bool TURLsMatch(const TemplateURL* turl1, const TemplateURL* turl2) { |
55 CHECK(turl1); | 58 CHECK(turl1); |
56 CHECK(turl2); | 59 CHECK(turl2); |
57 | 60 |
58 bool result = (turl1->url() == turl2->url()) && | 61 // Either both TemplateURLRefs are NULL or they're both valid and have the |
59 (turl1->keyword() == turl2->keyword()) && | 62 // same raw URL value. |
60 (turl1->short_name() == turl2->short_name()); | 63 bool urls_match = ((!turl1->url() && !turl1->url()) || |
| 64 (turl1->url() && turl2->url() && |
| 65 turl1->url()->url() == turl2->url()->url())); |
| 66 |
| 67 // Compare all major fields. |
| 68 bool result = (urls_match && turl1->keyword() == turl2->keyword() && |
| 69 turl1->short_name() == turl2->short_name()); |
61 | 70 |
62 // Print some useful debug info. | 71 // Print some useful debug info. |
63 if (!result) { | 72 if (!result) { |
64 LOG(ERROR) << "TemplateURLs did not match: " << GetTURLInfoString(turl1) | 73 LOG(ERROR) << "TemplateURLs did not match: " << GetTURLInfoString(turl1) |
65 << " vs " << GetTURLInfoString(turl2); | 74 << " vs " << GetTURLInfoString(turl2); |
66 } | 75 } |
67 | 76 |
68 return result; | 77 return result; |
69 } | 78 } |
70 | 79 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 const TemplateURL* default_a = service_a->GetDefaultSearchProvider(); | 141 const TemplateURL* default_a = service_a->GetDefaultSearchProvider(); |
133 const TemplateURL* default_b = service_b->GetDefaultSearchProvider(); | 142 const TemplateURL* default_b = service_b->GetDefaultSearchProvider(); |
134 CHECK(default_a); | 143 CHECK(default_a); |
135 CHECK(default_b); | 144 CHECK(default_b); |
136 if (!TURLsMatch(default_a, default_b)) { | 145 if (!TURLsMatch(default_a, default_b)) { |
137 LOG(ERROR) << "Default search providers do not match: A's default: " | 146 LOG(ERROR) << "Default search providers do not match: A's default: " |
138 << default_a->keyword() << " B's default: " | 147 << default_a->keyword() << " B's default: " |
139 << default_b->keyword(); | 148 << default_b->keyword(); |
140 return false; | 149 return false; |
141 } else { | 150 } else { |
142 LOG(INFO) << "A had default with URL: " << default_a->url() | 151 LOG(INFO) << "A had default with URL: " << default_a->url()->url() |
143 << " and keyword: " << default_a->keyword(); | 152 << " and keyword: " << default_a->keyword(); |
144 } | 153 } |
145 | 154 |
146 return true; | 155 return true; |
147 } | 156 } |
148 | 157 |
149 bool AllServicesMatch() { | 158 bool AllServicesMatch() { |
150 // Use 0 as the baseline. | 159 // Use 0 as the baseline. |
151 if (test()->use_verifier() && !ServiceMatchesVerifier(0)) { | 160 if (test()->use_verifier() && !ServiceMatchesVerifier(0)) { |
152 LOG(ERROR) << "TemplateURLService 0 does not match verifier."; | 161 LOG(ERROR) << "TemplateURLService 0 does not match verifier."; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 service->SetDefaultSearchProvider(turl); | 262 service->SetDefaultSearchProvider(turl); |
254 if (test()->use_verifier()) { | 263 if (test()->use_verifier()) { |
255 const TemplateURL* verifier_turl = | 264 const TemplateURL* verifier_turl = |
256 GetVerifierService()->GetTemplateURLForKeyword(CreateKeyword(seed)); | 265 GetVerifierService()->GetTemplateURLForKeyword(CreateKeyword(seed)); |
257 ASSERT_TRUE(verifier_turl); | 266 ASSERT_TRUE(verifier_turl); |
258 GetVerifierService()->SetDefaultSearchProvider(verifier_turl); | 267 GetVerifierService()->SetDefaultSearchProvider(verifier_turl); |
259 } | 268 } |
260 } | 269 } |
261 | 270 |
262 } // namespace search_engines_helper | 271 } // namespace search_engines_helper |
OLD | NEW |