| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_browsertest.h" | 5 #include "chrome/browser/extensions/extension_browsertest.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // This makes sure that we create the Default profile first, with no | 64 // This makes sure that we create the Default profile first, with no |
| 65 // ExtensionService and then the real profile with one, as we do when | 65 // ExtensionService and then the real profile with one, as we do when |
| 66 // running on chromeos. | 66 // running on chromeos. |
| 67 command_line->AppendSwitchASCII(switches::kLoginUser, | 67 command_line->AppendSwitchASCII(switches::kLoginUser, |
| 68 "TestUser@gmail.com"); | 68 "TestUser@gmail.com"); |
| 69 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 69 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
| 70 command_line->AppendSwitch(switches::kNoFirstRun); | 70 command_line->AppendSwitch(switches::kNoFirstRun); |
| 71 #endif | 71 #endif |
| 72 } | 72 } |
| 73 | 73 |
| 74 const Extension* ExtensionBrowserTest::LoadExtensionWithOptions( | 74 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags( |
| 75 const FilePath& path, bool incognito_enabled, bool fileaccess_enabled) { | 75 const FilePath& path, int flags) { |
| 76 ExtensionService* service = browser()->profile()->GetExtensionService(); | 76 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 77 { | 77 { |
| 78 content::NotificationRegistrar registrar; | 78 content::NotificationRegistrar registrar; |
| 79 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 79 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 80 content::NotificationService::AllSources()); | 80 content::NotificationService::AllSources()); |
| 81 scoped_refptr<extensions::UnpackedInstaller> installer( | 81 scoped_refptr<extensions::UnpackedInstaller> installer( |
| 82 extensions::UnpackedInstaller::Create(service)); | 82 extensions::UnpackedInstaller::Create(service)); |
| 83 installer->set_prompt_for_plugins(false); | 83 installer->set_prompt_for_plugins(false); |
| 84 installer->Load(path); | 84 installer->Load(path); |
| 85 content::RunMessageLoop(); | 85 content::RunMessageLoop(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Find the loaded extension by its path. See crbug.com/59531 for why | 88 // Find the loaded extension by its path. See crbug.com/59531 for why |
| 89 // we cannot just use last_loaded_extension_id_. | 89 // we cannot just use last_loaded_extension_id_. |
| 90 FilePath extension_path = path; | 90 FilePath extension_path = path; |
| 91 file_util::AbsolutePath(&extension_path); | 91 file_util::AbsolutePath(&extension_path); |
| 92 const Extension* extension = NULL; | 92 const Extension* extension = NULL; |
| 93 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | 93 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); |
| 94 iter != service->extensions()->end(); ++iter) { | 94 iter != service->extensions()->end(); ++iter) { |
| 95 if ((*iter)->path() == extension_path) { | 95 if ((*iter)->path() == extension_path) { |
| 96 extension = *iter; | 96 extension = *iter; |
| 97 break; | 97 break; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 if (!extension) | 100 if (!extension) |
| 101 return NULL; | 101 return NULL; |
| 102 | 102 |
| 103 if (!(flags & kFlagIgnoreManifestWarnings)) { |
| 104 const Extension::InstallWarningVector& install_warnings = |
| 105 extension->install_warnings(); |
| 106 if (!install_warnings.empty()) { |
| 107 std::string install_warnings_message = StringPrintf( |
| 108 "Unexpected warnings when loading test extension %s:\n", |
| 109 path.AsUTF8Unsafe().c_str()); |
| 110 |
| 111 for (Extension::InstallWarningVector::const_iterator it = |
| 112 install_warnings.begin(); it != install_warnings.end(); ++it) { |
| 113 install_warnings_message += " " + it->message + "\n"; |
| 114 } |
| 115 |
| 116 EXPECT_TRUE(extension->install_warnings().empty()) << |
| 117 install_warnings_message; |
| 118 return NULL; |
| 119 } |
| 120 } |
| 121 |
| 103 const std::string extension_id = extension->id(); | 122 const std::string extension_id = extension->id(); |
| 104 | 123 |
| 105 // The call to OnExtensionInstalled ensures the other extension prefs | 124 // The call to OnExtensionInstalled ensures the other extension prefs |
| 106 // are set up with the defaults. | 125 // are set up with the defaults. |
| 107 service->extension_prefs()->OnExtensionInstalled( | 126 service->extension_prefs()->OnExtensionInstalled( |
| 108 extension, Extension::ENABLED, false, | 127 extension, Extension::ENABLED, false, |
| 109 StringOrdinal::CreateInitialOrdinal()); | 128 StringOrdinal::CreateInitialOrdinal()); |
| 110 | 129 |
| 111 // Toggling incognito or file access will reload the extension, so wait for | 130 // Toggling incognito or file access will reload the extension, so wait for |
| 112 // the reload and grab the new extension instance. The default state is | 131 // the reload and grab the new extension instance. The default state is |
| 113 // incognito disabled and file access enabled, so we don't wait in those | 132 // incognito disabled and file access enabled, so we don't wait in those |
| 114 // cases. | 133 // cases. |
| 115 { | 134 { |
| 116 content::WindowedNotificationObserver load_signal( | 135 content::WindowedNotificationObserver load_signal( |
| 117 chrome::NOTIFICATION_EXTENSION_LOADED, | 136 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 118 content::Source<Profile>(browser()->profile())); | 137 content::Source<Profile>(browser()->profile())); |
| 119 CHECK(!service->IsIncognitoEnabled(extension_id)); | 138 CHECK(!service->IsIncognitoEnabled(extension_id)); |
| 120 | 139 |
| 121 if (incognito_enabled) { | 140 if (flags & kFlagEnableIncognito) { |
| 122 service->SetIsIncognitoEnabled(extension_id, incognito_enabled); | 141 service->SetIsIncognitoEnabled(extension_id, true); |
| 123 load_signal.Wait(); | 142 load_signal.Wait(); |
| 124 extension = service->GetExtensionById(extension_id, false); | 143 extension = service->GetExtensionById(extension_id, false); |
| 125 CHECK(extension) << extension_id << " not found after reloading."; | 144 CHECK(extension) << extension_id << " not found after reloading."; |
| 126 } | 145 } |
| 127 } | 146 } |
| 128 | 147 |
| 129 { | 148 { |
| 130 content::WindowedNotificationObserver load_signal( | 149 content::WindowedNotificationObserver load_signal( |
| 131 chrome::NOTIFICATION_EXTENSION_LOADED, | 150 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 132 content::Source<Profile>(browser()->profile())); | 151 content::Source<Profile>(browser()->profile())); |
| 133 CHECK(service->AllowFileAccess(extension)); | 152 CHECK(service->AllowFileAccess(extension)); |
| 134 if (!fileaccess_enabled) { | 153 if (!(flags & kFlagEnableFileAccess)) { |
| 135 service->SetAllowFileAccess(extension, fileaccess_enabled); | 154 service->SetAllowFileAccess(extension, false); |
| 136 load_signal.Wait(); | 155 load_signal.Wait(); |
| 137 extension = service->GetExtensionById(extension_id, false); | 156 extension = service->GetExtensionById(extension_id, false); |
| 138 CHECK(extension) << extension_id << " not found after reloading."; | 157 CHECK(extension) << extension_id << " not found after reloading."; |
| 139 } | 158 } |
| 140 } | 159 } |
| 141 | 160 |
| 142 if (!WaitForExtensionViewsToLoad()) | 161 if (!WaitForExtensionViewsToLoad()) |
| 143 return NULL; | 162 return NULL; |
| 144 | 163 |
| 145 return extension; | 164 return extension; |
| 146 } | 165 } |
| 147 | 166 |
| 148 const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) { | 167 const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) { |
| 149 return LoadExtensionWithOptions(path, false, true); | 168 return LoadExtensionWithFlags(path, kFlagEnableFileAccess); |
| 150 } | 169 } |
| 151 | 170 |
| 152 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( | 171 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( |
| 153 const FilePath& path) { | 172 const FilePath& path) { |
| 154 return LoadExtensionWithOptions(path, true, true); | 173 return LoadExtensionWithFlags(path, |
| 174 kFlagEnableFileAccess | kFlagEnableIncognito); |
| 155 } | 175 } |
| 156 | 176 |
| 157 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent( | 177 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent( |
| 158 const FilePath& path) { | 178 const FilePath& path) { |
| 159 ExtensionService* service = browser()->profile()->GetExtensionService(); | 179 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 160 | 180 |
| 161 std::string manifest; | 181 std::string manifest; |
| 162 if (!file_util::ReadFileToString(path.Append(Extension::kManifestFilename), | 182 if (!file_util::ReadFileToString(path.Append(Extension::kManifestFilename), |
| 163 &manifest)) | 183 &manifest)) |
| 164 return NULL; | 184 return NULL; |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 case content::NOTIFICATION_LOAD_STOP: | 672 case content::NOTIFICATION_LOAD_STOP: |
| 653 VLOG(1) << "Got LOAD_STOP notification."; | 673 VLOG(1) << "Got LOAD_STOP notification."; |
| 654 MessageLoopForUI::current()->Quit(); | 674 MessageLoopForUI::current()->Quit(); |
| 655 break; | 675 break; |
| 656 | 676 |
| 657 default: | 677 default: |
| 658 NOTREACHED(); | 678 NOTREACHED(); |
| 659 break; | 679 break; |
| 660 } | 680 } |
| 661 } | 681 } |
| OLD | NEW |