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

Side by Side Diff: chrome/browser/extensions/extension_updater_unittest.cc

Issue 3750001: base: Move SplitString functions into the base namespace and update the callers. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: brett review, reverted changes in o3d due to it's using an old base revision Created 10 years, 2 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <map> 5 #include <map>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 240
241 static const int kUpdateFrequencySecs = 15; 241 static const int kUpdateFrequencySecs = 15;
242 242
243 // Takes a string with KEY=VALUE parameters separated by '&' in |params| and 243 // Takes a string with KEY=VALUE parameters separated by '&' in |params| and
244 // puts the key/value pairs into |result|. For keys with no value, the empty 244 // puts the key/value pairs into |result|. For keys with no value, the empty
245 // string is used. So for "a=1&b=foo&c", result would map "a" to "1", "b" to 245 // string is used. So for "a=1&b=foo&c", result would map "a" to "1", "b" to
246 // "foo", and "c" to "". 246 // "foo", and "c" to "".
247 static void ExtractParameters(const std::string& params, 247 static void ExtractParameters(const std::string& params,
248 std::map<std::string, std::string>* result) { 248 std::map<std::string, std::string>* result) {
249 std::vector<std::string> pairs; 249 std::vector<std::string> pairs;
250 SplitString(params, '&', &pairs); 250 base::SplitString(params, '&', &pairs);
251 for (size_t i = 0; i < pairs.size(); i++) { 251 for (size_t i = 0; i < pairs.size(); i++) {
252 std::vector<std::string> key_val; 252 std::vector<std::string> key_val;
253 SplitString(pairs[i], '=', &key_val); 253 base::SplitString(pairs[i], '=', &key_val);
254 if (key_val.size() > 0) { 254 if (key_val.size() > 0) {
255 std::string key = key_val[0]; 255 std::string key = key_val[0];
256 EXPECT_TRUE(result->find(key) == result->end()); 256 EXPECT_TRUE(result->find(key) == result->end());
257 (*result)[key] = (key_val.size() == 2) ? key_val[1] : ""; 257 (*result)[key] = (key_val.size() == 2) ? key_val[1] : "";
258 } else { 258 } else {
259 NOTREACHED(); 259 NOTREACHED();
260 } 260 }
261 } 261 }
262 } 262 }
263 263
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 EXPECT_FALSE(url.is_empty()); 319 EXPECT_FALSE(url.is_empty());
320 EXPECT_TRUE(url.is_valid()); 320 EXPECT_TRUE(url.is_valid());
321 EXPECT_TRUE(url.SchemeIs("http")); 321 EXPECT_TRUE(url.SchemeIs("http"));
322 EXPECT_EQ("foo.com", url.host()); 322 EXPECT_EQ("foo.com", url.host());
323 EXPECT_EQ("/bar", url.path()); 323 EXPECT_EQ("/bar", url.path());
324 324
325 // Validate the extension request parameters in the query. It should 325 // Validate the extension request parameters in the query. It should
326 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". 326 // look something like "?x=id%3D<id>%26v%3D<version>%26uc".
327 EXPECT_TRUE(url.has_query()); 327 EXPECT_TRUE(url.has_query());
328 std::vector<std::string> parts; 328 std::vector<std::string> parts;
329 SplitString(url.query(), '=', &parts); 329 base::SplitString(url.query(), '=', &parts);
330 EXPECT_EQ(2u, parts.size()); 330 EXPECT_EQ(2u, parts.size());
331 EXPECT_EQ("x", parts[0]); 331 EXPECT_EQ("x", parts[0]);
332 std::string decoded = UnescapeURLComponent(parts[1], 332 std::string decoded = UnescapeURLComponent(parts[1],
333 UnescapeRule::URL_SPECIAL_CHARS); 333 UnescapeRule::URL_SPECIAL_CHARS);
334 std::map<std::string, std::string> params; 334 std::map<std::string, std::string> params;
335 ExtractParameters(decoded, &params); 335 ExtractParameters(decoded, &params);
336 if (pending) { 336 if (pending) {
337 EXPECT_EQ(pending_extensions.begin()->first, params["id"]); 337 EXPECT_EQ(pending_extensions.begin()->first, params["id"]);
338 EXPECT_EQ("0.0.0.0", params["v"]); 338 EXPECT_EQ("0.0.0.0", params["v"]);
339 } else { 339 } else {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 EXPECT_FALSE(url.is_empty()); 381 EXPECT_FALSE(url.is_empty());
382 EXPECT_TRUE(url.is_valid()); 382 EXPECT_TRUE(url.is_valid());
383 EXPECT_TRUE(url.SchemeIs("https")); 383 EXPECT_TRUE(url.SchemeIs("https"));
384 EXPECT_EQ("clients2.google.com", url.host()); 384 EXPECT_EQ("clients2.google.com", url.host());
385 EXPECT_EQ("/service/update2/crx", url.path()); 385 EXPECT_EQ("/service/update2/crx", url.path());
386 386
387 // Validate the extension request parameters in the query. It should 387 // Validate the extension request parameters in the query. It should
388 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". 388 // look something like "?x=id%3D<id>%26v%3D<version>%26uc".
389 EXPECT_TRUE(url.has_query()); 389 EXPECT_TRUE(url.has_query());
390 std::vector<std::string> parts; 390 std::vector<std::string> parts;
391 SplitString(url.query(), '=', &parts); 391 base::SplitString(url.query(), '=', &parts);
392 EXPECT_EQ(2u, parts.size()); 392 EXPECT_EQ(2u, parts.size());
393 EXPECT_EQ("x", parts[0]); 393 EXPECT_EQ("x", parts[0]);
394 std::string decoded = UnescapeURLComponent(parts[1], 394 std::string decoded = UnescapeURLComponent(parts[1],
395 UnescapeRule::URL_SPECIAL_CHARS); 395 UnescapeRule::URL_SPECIAL_CHARS);
396 std::map<std::string, std::string> params; 396 std::map<std::string, std::string> params;
397 ExtractParameters(decoded, &params); 397 ExtractParameters(decoded, &params);
398 EXPECT_EQ("com.google.crx.blacklist", params["id"]); 398 EXPECT_EQ("com.google.crx.blacklist", params["id"]);
399 EXPECT_EQ("0", params["v"]); 399 EXPECT_EQ("0", params["v"]);
400 EXPECT_EQ("", params["uc"]); 400 EXPECT_EQ("", params["uc"]);
401 EXPECT_TRUE(ContainsKey(params, "ping")); 401 EXPECT_TRUE(ContainsKey(params, "ping"));
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 // -prodversionmin (shouldn't update if browser version too old) 930 // -prodversionmin (shouldn't update if browser version too old)
931 // -manifests & updates arriving out of order / interleaved 931 // -manifests & updates arriving out of order / interleaved
932 // -Profile::GetDefaultRequestContext() returning null 932 // -Profile::GetDefaultRequestContext() returning null
933 // (should not crash, but just do check later) 933 // (should not crash, but just do check later)
934 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 934 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
935 // -An extension gets uninstalled while updates are in progress (so it doesn't 935 // -An extension gets uninstalled while updates are in progress (so it doesn't
936 // "come back from the dead") 936 // "come back from the dead")
937 // -An extension gets manually updated to v3 while we're downloading v2 (ie 937 // -An extension gets manually updated to v3 while we're downloading v2 (ie
938 // you don't get downgraded accidentally) 938 // you don't get downgraded accidentally)
939 // -An update manifest mentions multiple updates 939 // -An update manifest mentions multiple updates
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_updater.cc ('k') | chrome/browser/first_run/first_run_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698