Commit 6b6a6e69 authored by csorba@chromium.org's avatar csorba@chromium.org

Adding browsertest to verify that updating forced-installed extensions is possible.

BUG=237495

Review URL: https://chromiumcodereview.appspot.com/16102004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202624 0039d316-1c4b-4281-b951-d872f2087c98
parent 9b315e25
......@@ -12,6 +12,7 @@
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_utils.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
#include "net/base/upload_bytes_element_reader.h"
......@@ -54,6 +55,15 @@ net::URLRequestJob* BadRequestJobCallback(
request, network_delegate, headers, std::string(), true);
}
net::URLRequestJob* FileJobCallback(const base::FilePath& file_path,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) {
return new content::URLRequestMockHTTPJob(
request,
network_delegate,
file_path);
}
// Parses the upload data in |request| into |request_msg|, and validates the
// request. The query string in the URL must contain the |expected_type| for
// the "request" parameter. Returns true if all checks succeeded, and the
......@@ -254,4 +264,10 @@ TestRequestInterceptor::JobCallback TestRequestInterceptor::RegisterJob(
return base::Bind(&RegisterJobCallback, expected_type, expect_reregister);
}
// static
TestRequestInterceptor::JobCallback TestRequestInterceptor::FileJob(
const base::FilePath& file_path) {
return base::Bind(&FileJobCallback, file_path);
}
} // namespace policy
......@@ -11,6 +11,10 @@
#include "base/callback.h"
#include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
namespace base {
class FilePath;
}
namespace net {
class NetworkDelegate;
class URLRequest;
......@@ -56,6 +60,9 @@ class TestRequestInterceptor {
enterprise_management::DeviceRegisterRequest::Type expected_type,
bool expect_reregister);
// Returns a JobCallback that will send the contents of |file_path|.
static JobCallback FileJob(const base::FilePath& file_path);
private:
class Delegate;
......
......@@ -33,6 +33,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/extensions/updater/extension_updater.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/media_stream_devices_controller.h"
......@@ -40,6 +41,7 @@
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/policy/cloud/test_request_interceptor.h"
#include "chrome/browser/policy/mock_configuration_policy_provider.h"
#include "chrome/browser/policy/policy_map.h"
#include "chrome/browser/prefs/session_startup_pref.h"
......@@ -155,6 +157,10 @@ const char kHostedAppCrxId[] = "kbmnembihfiondgfjekmnmcbddelicoi";
const base::FilePath::CharType kGoodCrxManifestName[] =
FILE_PATH_LITERAL("good_update_manifest.xml");
const base::FilePath::CharType kGood2CrxManifestName[] =
FILE_PATH_LITERAL("good2_update_manifest.xml");
const base::FilePath::CharType kGoodV1CrxManifestName[] =
FILE_PATH_LITERAL("good_v1_update_manifest.xml");
const base::FilePath::CharType kGoodUnpackedExt[] =
FILE_PATH_LITERAL("good_unpacked");
const base::FilePath::CharType kAppUnpackedExt[] =
......@@ -1305,12 +1311,12 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallForcelist) {
// Extensions that are force-installed come from an update URL, which defaults
// to the webstore. Use a mock URL for this test with an update manifest
// that includes "good.crx".
// that includes "good_v1.crx".
base::FilePath path =
base::FilePath(kTestExtensionsDir).Append(kGoodCrxManifestName);
base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName);
GURL url(URLRequestMockHTTPJob::GetMockUrl(path));
// Setting the forcelist extension should install "good.crx".
// Setting the forcelist extension should install "good_v1.crx".
base::ListValue forcelist;
forcelist.Append(base::Value::CreateStringValue(base::StringPrintf(
"%s;%s", kGoodCrxId, url.spec().c_str())));
......@@ -1337,6 +1343,37 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallForcelist) {
// Loading other unpacked extensions are not blocked.
LoadUnpackedExtension(kAppUnpackedExt, true);
const std::string old_version_number =
service->GetExtensionById(kGoodCrxId, true)->version()->GetString();
base::FilePath test_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_path));
TestRequestInterceptor interceptor("update.extension");
interceptor.PushJobCallback(
TestRequestInterceptor::FileJob(
test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName)));
// Updating the force-installed extension.
extensions::ExtensionUpdater* updater = service->updater();
extensions::ExtensionUpdater::CheckParams params;
params.install_immediately = true;
content::WindowedNotificationObserver update_observer(
chrome::NOTIFICATION_EXTENSION_INSTALLED,
content::NotificationService::AllSources());
updater->CheckNow(params);
update_observer.Wait();
const base::Version* new_version =
service->GetExtensionById(kGoodCrxId, true)->version();
ASSERT_TRUE(new_version->IsValid());
base::Version old_version(old_version_number);
ASSERT_TRUE(old_version.IsValid());
EXPECT_EQ(1, new_version->CompareTo(old_version));
EXPECT_EQ(0u, interceptor.GetPendingSize());
}
IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment