Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 { | |
| 2668 public: | |
| 2669 Callback() | |
| 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); | |
|
Paweł Hajdan Jr.
2011/08/02 21:43:23
Why PostDelayedTask instead of doing it immediatel
ycxiao
2011/08/02 23:00:24
The callback of CookieMonster may be invoked immed
Paweł Hajdan Jr.
2011/08/02 23:29:59
Okay just get rid of PostDelayedTask.
| |
| 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 Callback 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(&Callback::SetCookieCallback, |
| 2717 base::Unretained(&callback))); | |
| 2718 loop_.RunAllPending(); | |
| 2719 EXPECT_TRUE(callback.result_); | |
| 2720 callback.message_loop_factory_.RevokeAll(); | |
| 2721 cookie_monster->GetAllCookiesForURLAsync( | |
| 2722 ext_url, | |
| 2723 base::Bind(&Callback::GetAllCookiesCallback, | |
| 2724 base::Unretained(&callback))); | |
| 2725 loop_.RunAllPending(); | |
| 2726 EXPECT_EQ(1U, callback.list_.size()); | |
| 2727 callback.message_loop_factory_.RevokeAll(); | |
| 2689 | 2728 |
| 2690 // Open a database. | 2729 // Open a database. |
| 2691 webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); | 2730 webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); |
| 2692 string16 db_name = UTF8ToUTF16("db"); | 2731 string16 db_name = UTF8ToUTF16("db"); |
| 2693 string16 description = UTF8ToUTF16("db_description"); | 2732 string16 description = UTF8ToUTF16("db_description"); |
| 2694 int64 size; | 2733 int64 size; |
| 2695 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); | 2734 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| 2696 db_tracker->DatabaseClosed(origin_id, db_name); | 2735 db_tracker->DatabaseClosed(origin_id, db_name); |
| 2697 std::vector<webkit_database::OriginInfo> origins; | 2736 std::vector<webkit_database::OriginInfo> origins; |
| 2698 db_tracker->GetAllOriginsInfo(&origins); | 2737 db_tracker->GetAllOriginsInfo(&origins); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2715 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); | 2754 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); |
| 2716 EXPECT_TRUE(file_util::CreateDirectory(idb_path.DirName())); | 2755 EXPECT_TRUE(file_util::CreateDirectory(idb_path.DirName())); |
| 2717 EXPECT_EQ(0, file_util::WriteFile(idb_path, NULL, 0)); | 2756 EXPECT_EQ(0, file_util::WriteFile(idb_path, NULL, 0)); |
| 2718 EXPECT_TRUE(file_util::PathExists(idb_path)); | 2757 EXPECT_TRUE(file_util::PathExists(idb_path)); |
| 2719 | 2758 |
| 2720 // Uninstall the extension. | 2759 // Uninstall the extension. |
| 2721 service_->UninstallExtension(good_crx, false, NULL); | 2760 service_->UninstallExtension(good_crx, false, NULL); |
| 2722 loop_.RunAllPending(); | 2761 loop_.RunAllPending(); |
| 2723 | 2762 |
| 2724 // Check that the cookie is gone. | 2763 // Check that the cookie is gone. |
| 2725 list = cookie_monster->GetAllCookiesForURL(ext_url); | 2764 cookie_monster->GetAllCookiesForURLAsync( |
| 2726 EXPECT_EQ(0U, list.size()); | 2765 ext_url, |
| 2766 base::Bind(&Callback::GetAllCookiesCallback, | |
| 2767 base::Unretained(&callback))); | |
| 2768 loop_.RunAllPending(); | |
| 2769 EXPECT_EQ(0U, callback.list_.size()); | |
| 2770 callback.message_loop_factory_.RevokeAll(); | |
| 2727 | 2771 |
| 2728 // The database should have vanished as well. | 2772 // The database should have vanished as well. |
| 2729 origins.clear(); | 2773 origins.clear(); |
| 2730 db_tracker->GetAllOriginsInfo(&origins); | 2774 db_tracker->GetAllOriginsInfo(&origins); |
| 2731 EXPECT_EQ(0U, origins.size()); | 2775 EXPECT_EQ(0U, origins.size()); |
| 2732 | 2776 |
| 2733 // Check that the LSO file has been removed. | 2777 // Check that the LSO file has been removed. |
| 2734 EXPECT_FALSE(file_util::PathExists(lso_path)); | 2778 EXPECT_FALSE(file_util::PathExists(lso_path)); |
| 2735 | 2779 |
| 2736 // Check if the indexed db has disappeared too. | 2780 // Check if the indexed db has disappeared too. |
| (...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3794 ASSERT_FALSE(AddPendingSyncInstall()); | 3838 ASSERT_FALSE(AddPendingSyncInstall()); |
| 3795 | 3839 |
| 3796 // Wait for the external source to install. | 3840 // Wait for the external source to install. |
| 3797 WaitForCrxInstall(crx_path_, true); | 3841 WaitForCrxInstall(crx_path_, true); |
| 3798 ASSERT_TRUE(IsCrxInstalled()); | 3842 ASSERT_TRUE(IsCrxInstalled()); |
| 3799 | 3843 |
| 3800 // Now that the extension is installed, sync request should fail | 3844 // Now that the extension is installed, sync request should fail |
| 3801 // because the extension is already installed. | 3845 // because the extension is already installed. |
| 3802 ASSERT_FALSE(AddPendingSyncInstall()); | 3846 ASSERT_FALSE(AddPendingSyncInstall()); |
| 3803 } | 3847 } |
| OLD | NEW |