diff options
author | limasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-07 00:23:21 +0000 |
---|---|---|
committer | limasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-07 00:23:21 +0000 |
commit | 3a44c45167c0aa6e2487f116b4c502c65e622190 (patch) | |
tree | 50d6385bb1a7f3c760023b0ec9a117cc7fa0eef0 /extensions | |
parent | 8952cde218e3bf28672382d2a920e2db5ecbedc2 (diff) | |
download | chromium_src-3a44c45167c0aa6e2487f116b4c502c65e622190.zip chromium_src-3a44c45167c0aa6e2487f116b4c502c65e622190.tar.gz chromium_src-3a44c45167c0aa6e2487f116b4c502c65e622190.tar.bz2 |
Move c/b/e/api/api_resource_manager_unittest.cc to
src/extensions/browser/api/
Make it compiled and fix typo.
BUG=381706
Review URL: https://codereview.chromium.org/319543006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275571 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/browser/api/api_resource_manager_unittest.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/extensions/browser/api/api_resource_manager_unittest.cc b/extensions/browser/api/api_resource_manager_unittest.cc new file mode 100644 index 0000000..0a86e0e --- /dev/null +++ b/extensions/browser/api/api_resource_manager_unittest.cc @@ -0,0 +1,63 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/files/file_path.h" +#include "base/strings/string_util.h" +#include "chrome/browser/extensions/extension_function_test_utils.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" +#include "extensions/browser/api/api_resource.h" +#include "extensions/browser/api/api_resource_manager.h" +#include "extensions/common/extension.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace utils = extension_function_test_utils; + +using content::BrowserThread; + +namespace extensions { + +class ApiResourceManagerUnitTest : public testing::Test { + private: + content::TestBrowserThreadBundle thread_bundle_; +}; + +class FakeApiResource : public ApiResource { + public: + explicit FakeApiResource(const std::string& owner_extension_id) + : ApiResource(owner_extension_id) {} + virtual ~FakeApiResource() {} + static const BrowserThread::ID kThreadId = BrowserThread::UI; +}; + +TEST_F(ApiResourceManagerUnitTest, TwoAppsCannotShareResources) { + scoped_ptr<ApiResourceManager<FakeApiResource> > manager( + new ApiResourceManager<FakeApiResource>(NULL)); + scoped_refptr<extensions::Extension> extension_one( + utils::CreateEmptyExtension("one")); + scoped_refptr<extensions::Extension> extension_two( + utils::CreateEmptyExtension("two")); + + const std::string extension_one_id(extension_one->id()); + const std::string extension_two_id(extension_two->id()); + + int resource_one_id = manager->Add(new FakeApiResource(extension_one_id)); + int resource_two_id = manager->Add(new FakeApiResource(extension_two_id)); + CHECK(resource_one_id); + CHECK(resource_two_id); + + // Confirm each extension can get its own resource. + ASSERT_TRUE(manager->Get(extension_one_id, resource_one_id) != NULL); + ASSERT_TRUE(manager->Get(extension_two_id, resource_two_id) != NULL); + + // Confirm neither extension can get the other's resource. + ASSERT_TRUE(manager->Get(extension_one_id, resource_two_id) == NULL); + ASSERT_TRUE(manager->Get(extension_two_id, resource_one_id) == NULL); + + // And make sure we're not susceptible to any Jedi mind tricks. + ASSERT_TRUE(manager->Get(std::string(), resource_one_id) == NULL); +} + +} // namespace extensions |