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

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

Issue 7550020: 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 Callback {
jstritar 2011/08/05 16:09:30 Could you rename this something more specific? Lik
ycxiao 2011/08/05 17:19:40 Sure, I will rename it when I back to office(I am
jstritar 2011/08/05 17:46:55 Thanks!
ycxiao 2011/08/06 18:43:27 Done.
2668 public:
2669 Callback()
2670 : result_(false),
2671 message_loop_factory_(MessageLoop::current()) {}
2672
2673 void SetCookieCallback(bool result) {
2674 MessageLoop::current()->PostTask(
2675 FROM_HERE,
2676 message_loop_factory_.NewRunnableMethod(&MessageLoop::Quit));
2677 result_ = result;
2678 }
2679
2680 void GetAllCookiesCallback(const net::CookieList& list) {
2681 MessageLoop::current()->PostTask(
2682 FROM_HERE,
2683 message_loop_factory_.NewRunnableMethod(&MessageLoop::Quit));
2684 list_ = list;
2685 }
2686 net::CookieList list_;
2687 bool result_;
2688 ScopedRunnableMethodFactory<MessageLoop> message_loop_factory_;
2689 };
2690
2666 // Verifies extension state is removed upon uninstall 2691 // Verifies extension state is removed upon uninstall
2667 TEST_F(ExtensionServiceTest, ClearExtensionData) { 2692 TEST_F(ExtensionServiceTest, ClearExtensionData) {
2668 InitializeEmptyExtensionService(); 2693 InitializeEmptyExtensionService();
2694 Callback callback;
2669 2695
2670 // Load a test extension. 2696 // Load a test extension.
2671 FilePath path = data_dir_; 2697 FilePath path = data_dir_;
2672 path = path.AppendASCII("good.crx"); 2698 path = path.AppendASCII("good.crx");
2673 InstallCrx(path, true); 2699 InstallCrx(path, true);
2674 const Extension* extension = service_->GetExtensionById(good_crx, false); 2700 const Extension* extension = service_->GetExtensionById(good_crx, false);
2675 ASSERT_TRUE(extension); 2701 ASSERT_TRUE(extension);
2676 GURL ext_url(extension->url()); 2702 GURL ext_url(extension->url());
2677 string16 origin_id = 2703 string16 origin_id =
2678 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); 2704 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url);
2679 2705
2680 // Set a cookie for the extension. 2706 // Set a cookie for the extension.
2681 net::CookieMonster* cookie_monster = 2707 net::CookieMonster* cookie_monster =
2682 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> 2708 profile_->GetRequestContextForExtensions()->GetURLRequestContext()->
2683 cookie_store()->GetCookieMonster(); 2709 cookie_store()->GetCookieMonster();
2684 ASSERT_TRUE(cookie_monster); 2710 ASSERT_TRUE(cookie_monster);
2685 net::CookieOptions options; 2711 net::CookieOptions options;
2686 cookie_monster->SetCookieWithOptions(ext_url, "dummy=value", options); 2712 cookie_monster->SetCookieWithOptionsAsync(
2687 net::CookieList list = cookie_monster->GetAllCookiesForURL(ext_url); 2713 ext_url, "dummy=value", options,
2688 EXPECT_EQ(1U, list.size()); 2714 base::Bind(&Callback::SetCookieCallback,
2715 base::Unretained(&callback)));
2716 loop_.RunAllPending();
2717 EXPECT_TRUE(callback.result_);
2718 callback.message_loop_factory_.RevokeAll();
2719 cookie_monster->GetAllCookiesForURLAsync(
2720 ext_url,
2721 base::Bind(&Callback::GetAllCookiesCallback,
2722 base::Unretained(&callback)));
2723 loop_.RunAllPending();
2724 EXPECT_EQ(1U, callback.list_.size());
2725 callback.message_loop_factory_.RevokeAll();
jstritar 2011/08/05 16:05:06 I'm not that familiar with the message loop code..
ycxiao 2011/08/05 17:19:40 This RevokeAlls is a ScopedRunnableMethodFactory m
jstritar 2011/08/05 17:46:55 Are they actually needed since you call loop_.RunA
ycxiao 2011/08/06 18:43:27 I think you are right. I removed the RevokeAll().
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(&Callback::GetAllCookiesCallback,
2765 base::Unretained(&callback)));
2766 loop_.RunAllPending();
2767 EXPECT_EQ(0U, callback.list_.size());
2768 callback.message_loop_factory_.RevokeAll();
2727 2769
2728 // The database should have vanished as well. 2770 // The database should have vanished as well.
2729 origins.clear(); 2771 origins.clear();
2730 db_tracker->GetAllOriginsInfo(&origins); 2772 db_tracker->GetAllOriginsInfo(&origins);
2731 EXPECT_EQ(0U, origins.size()); 2773 EXPECT_EQ(0U, origins.size());
2732 2774
2733 // Check that the LSO file has been removed. 2775 // Check that the LSO file has been removed.
2734 EXPECT_FALSE(file_util::PathExists(lso_path)); 2776 EXPECT_FALSE(file_util::PathExists(lso_path));
2735 2777
2736 // Check if the indexed db has disappeared too. 2778 // Check if the indexed db has disappeared too.
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
3794 ASSERT_FALSE(AddPendingSyncInstall()); 3836 ASSERT_FALSE(AddPendingSyncInstall());
3795 3837
3796 // Wait for the external source to install. 3838 // Wait for the external source to install.
3797 WaitForCrxInstall(crx_path_, true); 3839 WaitForCrxInstall(crx_path_, true);
3798 ASSERT_TRUE(IsCrxInstalled()); 3840 ASSERT_TRUE(IsCrxInstalled());
3799 3841
3800 // Now that the extension is installed, sync request should fail 3842 // Now that the extension is installed, sync request should fail
3801 // because the extension is already installed. 3843 // because the extension is already installed.
3802 ASSERT_FALSE(AddPendingSyncInstall()); 3844 ASSERT_FALSE(AddPendingSyncInstall());
3803 } 3845 }
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