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 ExtensionCookieCallback { |
| 2668 public: |
| 2669 ExtensionCookieCallback() |
| 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 ExtensionCookieCallback 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(&ExtensionCookieCallback::SetCookieCallback, |
| 2715 base::Unretained(&callback))); |
| 2716 loop_.RunAllPending(); |
| 2717 EXPECT_TRUE(callback.result_); |
| 2718 |
| 2719 cookie_monster->GetAllCookiesForURLAsync( |
| 2720 ext_url, |
| 2721 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 2722 base::Unretained(&callback))); |
| 2723 loop_.RunAllPending(); |
| 2724 EXPECT_EQ(1U, callback.list_.size()); |
2689 | 2725 |
2690 // Open a database. | 2726 // Open a database. |
2691 webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); | 2727 webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); |
2692 string16 db_name = UTF8ToUTF16("db"); | 2728 string16 db_name = UTF8ToUTF16("db"); |
2693 string16 description = UTF8ToUTF16("db_description"); | 2729 string16 description = UTF8ToUTF16("db_description"); |
2694 int64 size; | 2730 int64 size; |
2695 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); | 2731 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
2696 db_tracker->DatabaseClosed(origin_id, db_name); | 2732 db_tracker->DatabaseClosed(origin_id, db_name); |
2697 std::vector<webkit_database::OriginInfo> origins; | 2733 std::vector<webkit_database::OriginInfo> origins; |
2698 db_tracker->GetAllOriginsInfo(&origins); | 2734 db_tracker->GetAllOriginsInfo(&origins); |
(...skipping 16 matching lines...) Expand all Loading... |
2715 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); | 2751 FilePath idb_path = idb_context->GetIndexedDBFilePath(origin_id); |
2716 EXPECT_TRUE(file_util::CreateDirectory(idb_path.DirName())); | 2752 EXPECT_TRUE(file_util::CreateDirectory(idb_path.DirName())); |
2717 EXPECT_EQ(0, file_util::WriteFile(idb_path, NULL, 0)); | 2753 EXPECT_EQ(0, file_util::WriteFile(idb_path, NULL, 0)); |
2718 EXPECT_TRUE(file_util::PathExists(idb_path)); | 2754 EXPECT_TRUE(file_util::PathExists(idb_path)); |
2719 | 2755 |
2720 // Uninstall the extension. | 2756 // Uninstall the extension. |
2721 service_->UninstallExtension(good_crx, false, NULL); | 2757 service_->UninstallExtension(good_crx, false, NULL); |
2722 loop_.RunAllPending(); | 2758 loop_.RunAllPending(); |
2723 | 2759 |
2724 // Check that the cookie is gone. | 2760 // Check that the cookie is gone. |
2725 list = cookie_monster->GetAllCookiesForURL(ext_url); | 2761 cookie_monster->GetAllCookiesForURLAsync( |
2726 EXPECT_EQ(0U, list.size()); | 2762 ext_url, |
| 2763 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 2764 base::Unretained(&callback))); |
| 2765 loop_.RunAllPending(); |
| 2766 EXPECT_EQ(0U, callback.list_.size()); |
2727 | 2767 |
2728 // The database should have vanished as well. | 2768 // The database should have vanished as well. |
2729 origins.clear(); | 2769 origins.clear(); |
2730 db_tracker->GetAllOriginsInfo(&origins); | 2770 db_tracker->GetAllOriginsInfo(&origins); |
2731 EXPECT_EQ(0U, origins.size()); | 2771 EXPECT_EQ(0U, origins.size()); |
2732 | 2772 |
2733 // Check that the LSO file has been removed. | 2773 // Check that the LSO file has been removed. |
2734 EXPECT_FALSE(file_util::PathExists(lso_path)); | 2774 EXPECT_FALSE(file_util::PathExists(lso_path)); |
2735 | 2775 |
2736 // Check if the indexed db has disappeared too. | 2776 // Check if the indexed db has disappeared too. |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3796 ASSERT_FALSE(AddPendingSyncInstall()); | 3836 ASSERT_FALSE(AddPendingSyncInstall()); |
3797 | 3837 |
3798 // Wait for the external source to install. | 3838 // Wait for the external source to install. |
3799 WaitForCrxInstall(crx_path_, true); | 3839 WaitForCrxInstall(crx_path_, true); |
3800 ASSERT_TRUE(IsCrxInstalled()); | 3840 ASSERT_TRUE(IsCrxInstalled()); |
3801 | 3841 |
3802 // Now that the extension is installed, sync request should fail | 3842 // Now that the extension is installed, sync request should fail |
3803 // because the extension is already installed. | 3843 // because the extension is already installed. |
3804 ASSERT_FALSE(AddPendingSyncInstall()); | 3844 ASSERT_FALSE(AddPendingSyncInstall()); |
3805 } | 3845 } |
OLD | NEW |