| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/webstore_installer_test.h" | 8 #include "chrome/browser/extensions/webstore_installer_test.h" |
| 9 #include "chrome/browser/extensions/webstore_reinstaller.h" | 9 #include "chrome/browser/extensions/webstore_reinstaller.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 DictionaryBuilder().Set("name", kExtensionName) | 69 DictionaryBuilder().Set("name", kExtensionName) |
| 70 .Set("description", "Foo") | 70 .Set("description", "Foo") |
| 71 .Set("manifest_version", 2) | 71 .Set("manifest_version", 2) |
| 72 .Set("version", "1.0") | 72 .Set("version", "1.0") |
| 73 .Build()) | 73 .Build()) |
| 74 .Build(); | 74 .Build(); |
| 75 extension_service()->AddExtension(extension.get()); | 75 extension_service()->AddExtension(extension.get()); |
| 76 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 76 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 77 ASSERT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); | 77 ASSERT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); |
| 78 | 78 |
| 79 // WebstoreReinstaller expects corrupted extension. |
| 80 extension_service()->DisableExtension(kTestExtensionId, |
| 81 Extension::DISABLE_CORRUPTED); |
| 82 |
| 79 content::WebContents* active_web_contents = | 83 content::WebContents* active_web_contents = |
| 80 browser()->tab_strip_model()->GetActiveWebContents(); | 84 browser()->tab_strip_model()->GetActiveWebContents(); |
| 81 ASSERT_TRUE(active_web_contents); | 85 ASSERT_TRUE(active_web_contents); |
| 82 | 86 |
| 83 // Start by canceling the repair prompt. | 87 // Start by canceling the repair prompt. |
| 84 AutoCancelInstall(); | 88 AutoCancelInstall(); |
| 85 | 89 |
| 86 // Create and run a WebstoreReinstaller. | 90 // Create and run a WebstoreReinstaller. |
| 87 base::RunLoop run_loop; | 91 base::RunLoop run_loop; |
| 88 scoped_refptr<WebstoreReinstaller> reinstaller( | 92 scoped_refptr<WebstoreReinstaller> reinstaller( |
| 89 new WebstoreReinstaller( | 93 new WebstoreReinstaller( |
| 90 active_web_contents, | 94 active_web_contents, |
| 91 kTestExtensionId, | 95 kTestExtensionId, |
| 92 base::Bind(&WebstoreReinstallerBrowserTest::OnInstallCompletion, | 96 base::Bind(&WebstoreReinstallerBrowserTest::OnInstallCompletion, |
| 93 base::Unretained(this), | 97 base::Unretained(this), |
| 94 run_loop.QuitClosure()))); | 98 run_loop.QuitClosure()))); |
| 95 reinstaller->BeginReinstall(); | 99 reinstaller->BeginReinstall(); |
| 96 run_loop.Run(); | 100 run_loop.Run(); |
| 97 | 101 |
| 98 // We should have failed, and the old extension should still be present. | 102 // We should have failed, and the old extension should still be present. |
| 99 EXPECT_FALSE(last_install_result()); | 103 EXPECT_FALSE(last_install_result()); |
| 100 extension = registry->enabled_extensions().GetByID(kTestExtensionId); | 104 extension = registry->disabled_extensions().GetByID(kTestExtensionId); |
| 101 ASSERT_TRUE(extension.get()); | 105 ASSERT_TRUE(extension.get()); |
| 102 EXPECT_EQ(kExtensionName, extension->name()); | 106 EXPECT_EQ(kExtensionName, extension->name()); |
| 103 | 107 |
| 104 // Now accept the repair prompt. | 108 // Now accept the repair prompt. |
| 105 AutoAcceptInstall(); | 109 AutoAcceptInstall(); |
| 106 base::RunLoop run_loop2; | 110 base::RunLoop run_loop2; |
| 107 reinstaller = | 111 reinstaller = |
| 108 new WebstoreReinstaller( | 112 new WebstoreReinstaller( |
| 109 active_web_contents, | 113 active_web_contents, |
| 110 kTestExtensionId, | 114 kTestExtensionId, |
| 111 base::Bind(&WebstoreReinstallerBrowserTest::OnInstallCompletion, | 115 base::Bind(&WebstoreReinstallerBrowserTest::OnInstallCompletion, |
| 112 base::Unretained(this), | 116 base::Unretained(this), |
| 113 run_loop2.QuitClosure())); | 117 run_loop2.QuitClosure())); |
| 114 reinstaller->BeginReinstall(); | 118 reinstaller->BeginReinstall(); |
| 115 run_loop2.Run(); | 119 run_loop2.Run(); |
| 116 | 120 |
| 117 // The reinstall should have succeeded, and the extension should have been | 121 // The reinstall should have succeeded, and the extension should have been |
| 118 // "updated" (which in this case means that it should have been replaced with | 122 // "updated" (which in this case means that it should have been replaced with |
| 119 // the inline install test extension, since that's the id we used). | 123 // the inline install test extension, since that's the id we used). |
| 120 EXPECT_TRUE(last_install_result()); | 124 EXPECT_TRUE(last_install_result()); |
| 121 extension = registry->enabled_extensions().GetByID(kTestExtensionId); | 125 extension = registry->enabled_extensions().GetByID(kTestExtensionId); |
| 122 ASSERT_TRUE(extension.get()); | 126 ASSERT_TRUE(extension.get()); |
| 123 // The name should not match, since the extension changed. | 127 // The name should not match, since the extension changed. |
| 124 EXPECT_NE(kExtensionName, extension->name()); | 128 EXPECT_NE(kExtensionName, extension->name()); |
| 125 } | 129 } |
| 126 | 130 |
| 127 } // namespace extensions | 131 } // namespace extensions |
| OLD | NEW |