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 std::string shortname = UTF16ToASCII(turl->short_name()); | 50 return "TemplateURL: shortname: " + UTF16ToASCII(turl->short_name()) + |
51 std::string keyword = UTF16ToASCII(turl->keyword()); | 51 " keyword: " + UTF16ToASCII(turl->keyword()) + " url: " + turl->url(); |
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")); | |
55 } | 52 } |
56 | 53 |
57 bool TURLsMatch(const TemplateURL* turl1, const TemplateURL* turl2) { | 54 bool TURLsMatch(const TemplateURL* turl1, const TemplateURL* turl2) { |
58 CHECK(turl1); | 55 CHECK(turl1); |
59 CHECK(turl2); | 56 CHECK(turl2); |
60 | 57 |
61 // Either both TemplateURLRefs are NULL or they're both valid and have the | 58 bool result = (turl1->url() == turl2->url()) && |
62 // same raw URL value. | 59 (turl1->keyword() == turl2->keyword()) && |
63 bool urls_match = ((!turl1->url() && !turl1->url()) || | 60 (turl1->short_name() == turl2->short_name()); |
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()); | |
70 | 61 |
71 // Print some useful debug info. | 62 // Print some useful debug info. |
72 if (!result) { | 63 if (!result) { |
73 LOG(ERROR) << "TemplateURLs did not match: " << GetTURLInfoString(turl1) | 64 LOG(ERROR) << "TemplateURLs did not match: " << GetTURLInfoString(turl1) |
74 << " vs " << GetTURLInfoString(turl2); | 65 << " vs " << GetTURLInfoString(turl2); |
75 } | 66 } |
76 | 67 |
77 return result; | 68 return result; |
78 } | 69 } |
79 | 70 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 const TemplateURL* default_a = service_a->GetDefaultSearchProvider(); | 132 const TemplateURL* default_a = service_a->GetDefaultSearchProvider(); |
142 const TemplateURL* default_b = service_b->GetDefaultSearchProvider(); | 133 const TemplateURL* default_b = service_b->GetDefaultSearchProvider(); |
143 CHECK(default_a); | 134 CHECK(default_a); |
144 CHECK(default_b); | 135 CHECK(default_b); |
145 if (!TURLsMatch(default_a, default_b)) { | 136 if (!TURLsMatch(default_a, default_b)) { |
146 LOG(ERROR) << "Default search providers do not match: A's default: " | 137 LOG(ERROR) << "Default search providers do not match: A's default: " |
147 << default_a->keyword() << " B's default: " | 138 << default_a->keyword() << " B's default: " |
148 << default_b->keyword(); | 139 << default_b->keyword(); |
149 return false; | 140 return false; |
150 } else { | 141 } else { |
151 LOG(INFO) << "A had default with URL: " << default_a->url()->url() | 142 LOG(INFO) << "A had default with URL: " << default_a->url() |
152 << " and keyword: " << default_a->keyword(); | 143 << " and keyword: " << default_a->keyword(); |
153 } | 144 } |
154 | 145 |
155 return true; | 146 return true; |
156 } | 147 } |
157 | 148 |
158 bool AllServicesMatch() { | 149 bool AllServicesMatch() { |
159 // Use 0 as the baseline. | 150 // Use 0 as the baseline. |
160 if (test()->use_verifier() && !ServiceMatchesVerifier(0)) { | 151 if (test()->use_verifier() && !ServiceMatchesVerifier(0)) { |
161 LOG(ERROR) << "TemplateURLService 0 does not match verifier."; | 152 LOG(ERROR) << "TemplateURLService 0 does not match verifier."; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 service->SetDefaultSearchProvider(turl); | 253 service->SetDefaultSearchProvider(turl); |
263 if (test()->use_verifier()) { | 254 if (test()->use_verifier()) { |
264 const TemplateURL* verifier_turl = | 255 const TemplateURL* verifier_turl = |
265 GetVerifierService()->GetTemplateURLForKeyword(CreateKeyword(seed)); | 256 GetVerifierService()->GetTemplateURLForKeyword(CreateKeyword(seed)); |
266 ASSERT_TRUE(verifier_turl); | 257 ASSERT_TRUE(verifier_turl); |
267 GetVerifierService()->SetDefaultSearchProvider(verifier_turl); | 258 GetVerifierService()->SetDefaultSearchProvider(verifier_turl); |
268 } | 259 } |
269 } | 260 } |
270 | 261 |
271 } // namespace search_engines_helper | 262 } // namespace search_engines_helper |
OLD | NEW |