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

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

Issue 196097: Do not send or store cookies for extensions autoupdate http requests.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_updater.cc ('k') | chrome/browser/net/url_fetcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/thread.h" 11 #include "base/thread.h"
12 #include "chrome/browser/extensions/extension_updater.h" 12 #include "chrome/browser/extensions/extension_updater.h"
13 #include "chrome/browser/extensions/extensions_service.h" 13 #include "chrome/browser/extensions/extensions_service.h"
14 #include "chrome/browser/net/test_url_fetcher_factory.h" 14 #include "chrome/browser/net/test_url_fetcher_factory.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_constants.h" 16 #include "chrome/common/extensions/extension_constants.h"
17 #include "chrome/common/extensions/extension_error_reporter.h" 17 #include "chrome/common/extensions/extension_error_reporter.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/common/pref_service.h" 19 #include "chrome/common/pref_service.h"
20 #include "net/base/escape.h" 20 #include "net/base/escape.h"
21 #include "net/base/load_flags.h"
21 #include "net/url_request/url_request_status.h" 22 #include "net/url_request/url_request_status.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 #include "libxml/globals.h" 24 #include "libxml/globals.h"
24 25
25 26 static int expected_load_flags =
27 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES;
26 28
27 // Do-nothing base class for further specialized test classes. 29 // Do-nothing base class for further specialized test classes.
28 class MockService : public ExtensionUpdateService { 30 class MockService : public ExtensionUpdateService {
29 public: 31 public:
30 MockService() {} 32 MockService() {}
31 virtual ~MockService() {} 33 virtual ~MockService() {}
32 34
33 virtual const ExtensionList* extensions() const { 35 virtual const ExtensionList* extensions() const {
34 EXPECT_TRUE(false); 36 EXPECT_TRUE(false);
35 return NULL; 37 return NULL;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 GURL url2("http://localhost/manifest2"); 365 GURL url2("http://localhost/manifest2");
364 366
365 // Request 2 update checks - the first should begin immediately and the 367 // Request 2 update checks - the first should begin immediately and the
366 // second one should be queued up. 368 // second one should be queued up.
367 updater->StartUpdateCheck(url1); 369 updater->StartUpdateCheck(url1);
368 updater->StartUpdateCheck(url2); 370 updater->StartUpdateCheck(url2);
369 371
370 std::string invalid_xml = "invalid xml"; 372 std::string invalid_xml = "invalid xml";
371 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); 373 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId);
372 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 374 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
375 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags);
373 fetcher->delegate()->OnURLFetchComplete( 376 fetcher->delegate()->OnURLFetchComplete(
374 fetcher, url1, URLRequestStatus(), 200, ResponseCookies(), 377 fetcher, url1, URLRequestStatus(), 200, ResponseCookies(),
375 invalid_xml); 378 invalid_xml);
376 379
377 // Now that the first request is complete, make sure the second one has 380 // Now that the first request is complete, make sure the second one has
378 // been started. 381 // been started.
379 const std::string kValidXml = 382 const std::string kValidXml =
380 "<?xml version='1.0' encoding='UTF-8'?>" 383 "<?xml version='1.0' encoding='UTF-8'?>"
381 "<gupdate xmlns='http://www.google.com/update2/response'" 384 "<gupdate xmlns='http://www.google.com/update2/response'"
382 " protocol='2.0'>" 385 " protocol='2.0'>"
383 " <app appid='12345'>" 386 " <app appid='12345'>"
384 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'" 387 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
385 " version='1.2.3.4' prodversionmin='2.0.143.0' />" 388 " version='1.2.3.4' prodversionmin='2.0.143.0' />"
386 " </app>" 389 " </app>"
387 "</gupdate>"; 390 "</gupdate>";
388 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); 391 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId);
389 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 392 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
393 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags);
390 fetcher->delegate()->OnURLFetchComplete( 394 fetcher->delegate()->OnURLFetchComplete(
391 fetcher, url2, URLRequestStatus(), 200, ResponseCookies(), 395 fetcher, url2, URLRequestStatus(), 200, ResponseCookies(),
392 kValidXml); 396 kValidXml);
393 397
394 // This should run the manifest parsing, then we want to make sure that our 398 // This should run the manifest parsing, then we want to make sure that our
395 // service was called with GetExtensionById with the matching id from 399 // service was called with GetExtensionById with the matching id from
396 // kValidXml. 400 // kValidXml.
397 file_thread.Stop(); 401 file_thread.Stop();
398 io_thread.Stop(); 402 io_thread.Stop();
399 ui_loop.RunAllPending(); 403 ui_loop.RunAllPending();
(...skipping 20 matching lines...) Expand all
420 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 424 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
421 std::string hash = ""; 425 std::string hash = "";
422 std::string version = "0.0.1"; 426 std::string version = "0.0.1";
423 427
424 updater->FetchUpdatedExtension(id, test_url, hash, version); 428 updater->FetchUpdatedExtension(id, test_url, hash, version);
425 429
426 // Call back the ExtensionUpdater with a 200 response and some test data 430 // Call back the ExtensionUpdater with a 200 response and some test data
427 std::string extension_data("whatever"); 431 std::string extension_data("whatever");
428 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); 432 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId);
429 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 433 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
434 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags);
430 fetcher->delegate()->OnURLFetchComplete( 435 fetcher->delegate()->OnURLFetchComplete(
431 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(), 436 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(),
432 extension_data); 437 extension_data);
433 438
434 file_thread.Stop(); 439 file_thread.Stop();
435 ui_loop.RunAllPending(); 440 ui_loop.RunAllPending();
436 441
437 // Expect that ExtensionUpdater asked the mock extensions service to install 442 // Expect that ExtensionUpdater asked the mock extensions service to install
438 // a file with the test data for the right id. 443 // a file with the test data for the right id.
439 EXPECT_EQ(id, service.extension_id()); 444 EXPECT_EQ(id, service.extension_id());
(...skipping 27 matching lines...) Expand all
467 "2CE109E9D0FAF820B2434E166297934E6177B65AB9951DBC3E204CAD4689B39C"; 472 "2CE109E9D0FAF820B2434E166297934E6177B65AB9951DBC3E204CAD4689B39C";
468 473
469 std::string version = "0.0.1"; 474 std::string version = "0.0.1";
470 475
471 updater->FetchUpdatedExtension(id, test_url, hash, version); 476 updater->FetchUpdatedExtension(id, test_url, hash, version);
472 477
473 // Call back the ExtensionUpdater with a 200 response and some test data 478 // Call back the ExtensionUpdater with a 200 response and some test data
474 std::string extension_data("aaabbb"); 479 std::string extension_data("aaabbb");
475 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); 480 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId);
476 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 481 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
482 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags);
477 fetcher->delegate()->OnURLFetchComplete( 483 fetcher->delegate()->OnURLFetchComplete(
478 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(), 484 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(),
479 extension_data); 485 extension_data);
480 486
481 message_loop.RunAllPending(); 487 message_loop.RunAllPending();
482 488
483 // The updater should have called extension service to process the 489 // The updater should have called extension service to process the
484 // blacklist. 490 // blacklist.
485 EXPECT_TRUE(service.processed_blacklist()); 491 EXPECT_TRUE(service.processed_blacklist());
486 492
(...skipping 26 matching lines...) Expand all
513 std::string version1 = "0.1"; 519 std::string version1 = "0.1";
514 std::string version2 = "0.1"; 520 std::string version2 = "0.1";
515 // Start two fetches 521 // Start two fetches
516 updater->FetchUpdatedExtension(id1, url1, hash1, version1); 522 updater->FetchUpdatedExtension(id1, url1, hash1, version1);
517 updater->FetchUpdatedExtension(id2, url2, hash2, version2); 523 updater->FetchUpdatedExtension(id2, url2, hash2, version2);
518 524
519 // Make the first fetch complete. 525 // Make the first fetch complete.
520 std::string extension_data1("whatever"); 526 std::string extension_data1("whatever");
521 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); 527 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId);
522 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 528 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
529 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags);
523 fetcher->delegate()->OnURLFetchComplete( 530 fetcher->delegate()->OnURLFetchComplete(
524 fetcher, url1, URLRequestStatus(), 200, ResponseCookies(), 531 fetcher, url1, URLRequestStatus(), 200, ResponseCookies(),
525 extension_data1); 532 extension_data1);
526 message_loop.RunAllPending(); 533 message_loop.RunAllPending();
527 534
528 // Expect that the service was asked to do an install with the right data. 535 // Expect that the service was asked to do an install with the right data.
529 FilePath tmpfile_path = service.install_path(); 536 FilePath tmpfile_path = service.install_path();
530 EXPECT_FALSE(tmpfile_path.empty()); 537 EXPECT_FALSE(tmpfile_path.empty());
531 EXPECT_EQ(id1, service.extension_id()); 538 EXPECT_EQ(id1, service.extension_id());
532 message_loop.RunAllPending(); 539 message_loop.RunAllPending();
533 file_util::Delete(tmpfile_path, false); 540 file_util::Delete(tmpfile_path, false);
534 541
535 // Make sure the second fetch finished and asked the service to do an 542 // Make sure the second fetch finished and asked the service to do an
536 // update. 543 // update.
537 std::string extension_data2("whatever2"); 544 std::string extension_data2("whatever2");
538 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); 545 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId);
539 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 546 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
547 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags);
540 fetcher->delegate()->OnURLFetchComplete( 548 fetcher->delegate()->OnURLFetchComplete(
541 fetcher, url2, URLRequestStatus(), 200, ResponseCookies(), 549 fetcher, url2, URLRequestStatus(), 200, ResponseCookies(),
542 extension_data2); 550 extension_data2);
543 message_loop.RunAllPending(); 551 message_loop.RunAllPending();
544 EXPECT_EQ(id2, service.extension_id()); 552 EXPECT_EQ(id2, service.extension_id());
545 EXPECT_FALSE(service.install_path().empty()); 553 EXPECT_FALSE(service.install_path().empty());
546 554
547 // Make sure the correct crx contents were passed for the update call. 555 // Make sure the correct crx contents were passed for the update call.
548 std::string file_contents; 556 std::string file_contents;
549 EXPECT_TRUE(file_util::ReadFileToString(service.install_path(), 557 EXPECT_TRUE(file_util::ReadFileToString(service.install_path(),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // -prodversionmin (shouldn't update if browser version too old) 598 // -prodversionmin (shouldn't update if browser version too old)
591 // -manifests & updates arriving out of order / interleaved 599 // -manifests & updates arriving out of order / interleaved
592 // -Profile::GetDefaultRequestContext() returning null 600 // -Profile::GetDefaultRequestContext() returning null
593 // (should not crash, but just do check later) 601 // (should not crash, but just do check later)
594 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 602 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
595 // -An extension gets uninstalled while updates are in progress (so it doesn't 603 // -An extension gets uninstalled while updates are in progress (so it doesn't
596 // "come back from the dead") 604 // "come back from the dead")
597 // -An extension gets manually updated to v3 while we're downloading v2 (ie 605 // -An extension gets manually updated to v3 while we're downloading v2 (ie
598 // you don't get downgraded accidentally) 606 // you don't get downgraded accidentally)
599 // -An update manifest mentions multiple updates 607 // -An update manifest mentions multiple updates
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_updater.cc ('k') | chrome/browser/net/url_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698