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

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

Issue 7537039: Apply the new asynchronous CookieMonster API to extension_service_unittest.cc. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 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 | « no previous file | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/file_util.h" 14 #include "base/file_util.h"
14 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop.h" 17 #include "base/message_loop.h"
17 #include "base/path_service.h" 18 #include "base/path_service.h"
18 #include "base/scoped_temp_dir.h" 19 #include "base/scoped_temp_dir.h"
19 #include "base/stl_util.h" 20 #include "base/stl_util.h"
20 #include "base/string16.h" 21 #include "base/string16.h"
21 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
(...skipping 2634 matching lines...) Expand 10 before | Expand all | Expand 10 after
2656 UninstallExtension(good_crx, true); 2657 UninstallExtension(good_crx, true);
2657 } 2658 }
2658 2659
2659 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { 2660 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) {
2660 InitializeEmptyExtensionService(); 2661 InitializeEmptyExtensionService();
2661 InstallCrx(data_dir_.AppendASCII("good.crx"), true); 2662 InstallCrx(data_dir_.AppendASCII("good.crx"), true);
2662 TerminateExtension(good_crx); 2663 TerminateExtension(good_crx);
2663 UninstallExtension(good_crx, true); 2664 UninstallExtension(good_crx, true);
2664 } 2665 }
2665 2666
2667 class ExtensionCookieCallback {
2668 public:
2669 ExtensionCookieCallback()
2670 : result_(false),
2671 message_loop_factory_(MessageLoop::current()) {}
2672
2673 void SetCookieCallback(bool result) {
2674 MessageLoop::current()->PostDelayedTask(
2675 FROM_HERE,
2676 message_loop_factory_.NewRunnableMethod(&MessageLoop::Quit),
2677 10);
2678 result_ = result;
2679 }
2680
2681 void GetAllCookiesCallback(const net::CookieList& list) {
2682 MessageLoop::current()->PostDelayedTask(
2683 FROM_HERE,
2684 message_loop_factory_.NewRunnableMethod(&MessageLoop::Quit),
2685 10);
2686 list_ = list;
2687 }
2688 net::CookieList list_;
2689 bool result_;
2690 ScopedRunnableMethodFactory<MessageLoop> message_loop_factory_;
2691 };
2692
2666 // Verifies extension state is removed upon uninstall 2693 // Verifies extension state is removed upon uninstall
2667 TEST_F(ExtensionServiceTest, ClearExtensionData) { 2694 TEST_F(ExtensionServiceTest, ClearExtensionData) {
2668 InitializeEmptyExtensionService(); 2695 InitializeEmptyExtensionService();
2696 ExtensionCookieCallback callback;
2669 2697
2670 // Load a test extension. 2698 // Load a test extension.
2671 FilePath path = data_dir_; 2699 FilePath path = data_dir_;
2672 path = path.AppendASCII("good.crx"); 2700 path = path.AppendASCII("good.crx");
2673 InstallCrx(path, true); 2701 InstallCrx(path, true);
2674 const Extension* extension = service_->GetExtensionById(good_crx, false); 2702 const Extension* extension = service_->GetExtensionById(good_crx, false);
2675 ASSERT_TRUE(extension); 2703 ASSERT_TRUE(extension);
2676 GURL ext_url(extension->url()); 2704 GURL ext_url(extension->url());
2677 string16 origin_id = 2705 string16 origin_id =
2678 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); 2706 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url);
2679 2707
2680 // Set a cookie for the extension. 2708 // Set a cookie for the extension.
2681 net::CookieMonster* cookie_monster = 2709 net::CookieMonster* cookie_monster =
2682 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> 2710 profile_->GetRequestContextForExtensions()->GetURLRequestContext()->
2683 cookie_store()->GetCookieMonster(); 2711 cookie_store()->GetCookieMonster();
2684 ASSERT_TRUE(cookie_monster); 2712 ASSERT_TRUE(cookie_monster);
2685 net::CookieOptions options; 2713 net::CookieOptions options;
2686 cookie_monster->SetCookieWithOptions(ext_url, "dummy=value", options); 2714 cookie_monster->SetCookieWithOptionsAsync(
2687 net::CookieList list = cookie_monster->GetAllCookiesForURL(ext_url); 2715 ext_url, "dummy=value", options,
2688 EXPECT_EQ(1U, list.size()); 2716 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
2717 base::Unretained(&callback)));
2718 loop_.RunAllPending();
2719 EXPECT_TRUE(callback.result_);
2720 cookie_monster->GetAllCookiesForURLAsync(
2721 ext_url,
2722 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
2723 base::Unretained(&callback)));
2724 loop_.RunAllPending();
2725 EXPECT_EQ(1U, callback.list_.size());
2689 2726
2690 // Open a database. 2727 // Open a database.
2691 webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); 2728 webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker();
2692 string16 db_name = UTF8ToUTF16("db"); 2729 string16 db_name = UTF8ToUTF16("db");
2693 string16 description = UTF8ToUTF16("db_description"); 2730 string16 description = UTF8ToUTF16("db_description");
2694 int64 size; 2731 int64 size;
2695 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); 2732 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
2696 db_tracker->DatabaseClosed(origin_id, db_name); 2733 db_tracker->DatabaseClosed(origin_id, db_name);
2697 std::vector<webkit_database::OriginInfo> origins; 2734 std::vector<webkit_database::OriginInfo> origins;
2698 db_tracker->GetAllOriginsInfo(&origins); 2735 db_tracker->GetAllOriginsInfo(&origins);
(...skipping 16 matching lines...) Expand all
2715 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); 2752 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id);
2716 EXPECT_TRUE(file_util::CreateDirectory(idb_path.DirName())); 2753 EXPECT_TRUE(file_util::CreateDirectory(idb_path.DirName()));
2717 EXPECT_EQ(0, file_util::WriteFile(idb_path, NULL, 0)); 2754 EXPECT_EQ(0, file_util::WriteFile(idb_path, NULL, 0));
2718 EXPECT_TRUE(file_util::PathExists(idb_path)); 2755 EXPECT_TRUE(file_util::PathExists(idb_path));
2719 2756
2720 // Uninstall the extension. 2757 // Uninstall the extension.
2721 service_->UninstallExtension(good_crx, false, NULL); 2758 service_->UninstallExtension(good_crx, false, NULL);
2722 loop_.RunAllPending(); 2759 loop_.RunAllPending();
2723 2760
2724 // Check that the cookie is gone. 2761 // Check that the cookie is gone.
2725 list = cookie_monster->GetAllCookiesForURL(ext_url); 2762 cookie_monster->GetAllCookiesForURLAsync(
2726 EXPECT_EQ(0U, list.size()); 2763 ext_url,
2764 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
2765 base::Unretained(&callback)));
2766 loop_.RunAllPending();
2767 EXPECT_EQ(0U, callback.list_.size());
2727 2768
2728 // The database should have vanished as well. 2769 // The database should have vanished as well.
2729 origins.clear(); 2770 origins.clear();
2730 db_tracker->GetAllOriginsInfo(&origins); 2771 db_tracker->GetAllOriginsInfo(&origins);
2731 EXPECT_EQ(0U, origins.size()); 2772 EXPECT_EQ(0U, origins.size());
2732 2773
2733 // Check that the LSO file has been removed. 2774 // Check that the LSO file has been removed.
2734 EXPECT_FALSE(file_util::PathExists(lso_path)); 2775 EXPECT_FALSE(file_util::PathExists(lso_path));
2735 2776
2736 // Check if the indexed db has disappeared too. 2777 // Check if the indexed db has disappeared too.
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
3796 ASSERT_FALSE(AddPendingSyncInstall()); 3837 ASSERT_FALSE(AddPendingSyncInstall());
3797 3838
3798 // Wait for the external source to install. 3839 // Wait for the external source to install.
3799 WaitForCrxInstall(crx_path_, true); 3840 WaitForCrxInstall(crx_path_, true);
3800 ASSERT_TRUE(IsCrxInstalled()); 3841 ASSERT_TRUE(IsCrxInstalled());
3801 3842
3802 // Now that the extension is installed, sync request should fail 3843 // Now that the extension is installed, sync request should fail
3803 // because the extension is already installed. 3844 // because the extension is already installed.
3804 ASSERT_FALSE(AddPendingSyncInstall()); 3845 ASSERT_FALSE(AddPendingSyncInstall());
3805 } 3846 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698