Commit f5fa6d69 authored by hanxi's avatar hanxi Committed by Commit bot

Revert of media: Implement MediaDrmStorageImpl with tests (patchset #4...

Revert of media: Implement MediaDrmStorageImpl with tests (patchset #4 id:60001 of https://codereview.chromium.org/2791903004/ )

Reason for revert:
This CL causes MediaDrmStorageImplTest failing on chromium.linux/Android Tests:
https://uberchromegw.corp.google.com/i/chromium.linux/builders/Android%20Tests/builds/40330

BUG=709601

Original issue's description:
> media: Implement MediaDrmStorageImpl with tests
>
> Implement MediaDrmStorageImpl using PrefService.
>
> TBR=sdefresne@chromium.org
> BUG=493521
> TEST=New unit tests added.
>
> Review-Url: https://codereview.chromium.org/2791903004
> Cr-Commit-Position: refs/heads/master@{#462929}
> Committed: https://chromium.googlesource.com/chromium/src/+/d0b7b3b7e9f7d4e4c1f8276c5b416eaa05ac9bb0

TBR=yucliu@chromium.org,sdefresne@chromium.org,xhwang@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=493521

Review-Url: https://codereview.chromium.org/2808563002
Cr-Commit-Position: refs/heads/master@{#462988}
parent c93b0b62
...@@ -242,7 +242,6 @@ test("components_unittests") { ...@@ -242,7 +242,6 @@ test("components_unittests") {
if (is_android) { if (is_android) {
deps += [ deps += [
"//components/cdm/browser:unit_tests",
"//components/feature_engagement_tracker:unit_tests", "//components/feature_engagement_tracker:unit_tests",
"//components/gcm_driver/instance_id:test_support", "//components/gcm_driver/instance_id:test_support",
"//components/gcm_driver/instance_id/android:instance_id_driver_java", "//components/gcm_driver/instance_id/android:instance_id_driver_java",
......
...@@ -21,17 +21,3 @@ source_set("browser") { ...@@ -21,17 +21,3 @@ source_set("browser") {
"//media/mojo/interfaces", "//media/mojo/interfaces",
] ]
} }
source_set("unit_tests") {
testonly = true
sources = [
"media_drm_storage_impl_unittest.cc",
]
deps = [
":browser",
"//base/test:test_support",
"//components/prefs:test_support",
"//media/mojo/services",
"//testing/gtest",
]
}
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef COMPONENTS_CDM_BROWSER_MEDIA_DRM_STORAGE_IMPL_H_ #ifndef COMPONENTS_CDM_BROWSER_MEDIA_DRM_STORAGE_IMPL_H_
#define COMPONENTS_CDM_BROWSER_MEDIA_DRM_STORAGE_IMPL_H_ #define COMPONENTS_CDM_BROWSER_MEDIA_DRM_STORAGE_IMPL_H_
#include "base/threading/thread_checker.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "media/mojo/interfaces/media_drm_storage.mojom.h" #include "media/mojo/interfaces/media_drm_storage.mojom.h"
...@@ -54,15 +53,12 @@ class MediaDrmStorageImpl final : public media::mojom::MediaDrmStorage, ...@@ -54,15 +53,12 @@ class MediaDrmStorageImpl final : public media::mojom::MediaDrmStorage,
void DidFinishNavigation(content::NavigationHandle* navigation_handle) final; void DidFinishNavigation(content::NavigationHandle* navigation_handle) final;
private: private:
base::ThreadChecker thread_checker_;
// Stops observing WebContents and delete |this|. // Stops observing WebContents and delete |this|.
void Close(); void Close();
content::RenderFrameHost* const render_frame_host_ = nullptr; content::RenderFrameHost* const render_frame_host_ = nullptr;
PrefService* const pref_service_ = nullptr; PrefService* const pref_service_ = nullptr;
const url::Origin origin_; const url::Origin origin_;
const std::string origin_string_;
bool initialized_ = false; bool initialized_ = false;
mojo::Binding<media::mojom::MediaDrmStorage> binding_; mojo::Binding<media::mojom::MediaDrmStorage> binding_;
......
// Copyright 2017 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 "components/cdm/browser/media_drm_storage_impl.h"
#include <memory>
#include "base/run_loop.h"
#include "base/test/test_message_loop.h"
#include "components/prefs/testing_pref_service.h"
#include "media/mojo/services/mojo_media_drm_storage.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace cdm {
const char kMediaDrmStorage[] = "media.media_drm_storage";
const char kTestOrigin[] = "https://www.testorigin.com:80";
class MediaDrmStorageImplTest : public ::testing::Test {
public:
MediaDrmStorageImplTest() {}
void SetUp() override {
pref_service_.reset(new TestingPrefServiceSimple());
PrefRegistrySimple* registry = pref_service_->registry();
MediaDrmStorageImpl::RegisterProfilePrefs(registry);
media::mojom::MediaDrmStoragePtr media_drm_storage_ptr;
auto request = mojo::MakeRequest(&media_drm_storage_ptr);
media_drm_storage_.reset(
new media::MojoMediaDrmStorage(std::move(media_drm_storage_ptr)));
// The created object will be destroyed on connection error.
new MediaDrmStorageImpl(nullptr, // Use null RenderFrameHost for testing.
pref_service_.get(), url::Origin(GURL(kTestOrigin)),
std::move(request));
media_drm_storage_->Initialize(url::Origin(GURL(kTestOrigin)));
}
void TearDown() override {
media_drm_storage_.reset();
base::RunLoop().RunUntilIdle();
}
protected:
using SessionData = media::MediaDrmStorage::SessionData;
void OnProvisioned() {
media_drm_storage_->OnProvisioned(ExpectResult(true));
}
void SavePersistentSession(const std::string& session_id,
const std::vector<uint8_t>& key_set_id,
const std::string& mime_type,
bool success = true) {
media_drm_storage_->SavePersistentSession(
session_id, SessionData(key_set_id, mime_type), ExpectResult(success));
}
void LoadPersistentSession(const std::string& session_id,
const std::vector<uint8_t>& expected_key_set_id,
const std::string& expected_mime_type) {
media_drm_storage_->LoadPersistentSession(
session_id, ExpectResult(base::MakeUnique<SessionData>(
expected_key_set_id, expected_mime_type)));
}
void LoadPersistentSessionAndExpectFailure(const std::string& session_id) {
media_drm_storage_->LoadPersistentSession(
session_id, ExpectResult(std::unique_ptr<SessionData>()));
}
void RemovePersistentSession(const std::string& session_id,
bool success = true) {
media_drm_storage_->RemovePersistentSession(session_id,
ExpectResult(success));
}
void SaveAndLoadPersistentSession(const std::string& session_id,
const std::vector<uint8_t>& key_set_id,
const std::string& mime_type) {
SavePersistentSession(session_id, key_set_id, mime_type);
LoadPersistentSession(session_id, key_set_id, mime_type);
}
media::MediaDrmStorage::ResultCB ExpectResult(bool expected_result) {
return base::BindOnce(&MediaDrmStorageImplTest::CheckResult,
base::Unretained(this), expected_result);
}
media::MediaDrmStorage::LoadPersistentSessionCB ExpectResult(
std::unique_ptr<SessionData> expected_session_data) {
return base::BindOnce(&MediaDrmStorageImplTest::CheckLoadedSession,
base::Unretained(this),
base::Passed(&expected_session_data));
}
void CheckResult(bool expected_result, bool result) {
EXPECT_EQ(expected_result, result);
}
void CheckLoadedSession(std::unique_ptr<SessionData> expected_session_data,
std::unique_ptr<SessionData> session_data) {
if (!expected_session_data) {
EXPECT_FALSE(session_data);
return;
}
EXPECT_EQ(expected_session_data->key_set_id, session_data->key_set_id);
EXPECT_EQ(expected_session_data->mime_type, session_data->mime_type);
}
base::TestMessageLoop message_loop_;
std::unique_ptr<TestingPrefServiceSimple> pref_service_;
std::unique_ptr<media::MediaDrmStorage> media_drm_storage_;
};
TEST_F(MediaDrmStorageImplTest, OnProvisioned) {
OnProvisioned();
base::RunLoop().RunUntilIdle();
// Verify the origin dictionary is created.
const base::DictionaryValue* storage_dict =
pref_service_->GetDictionary(kMediaDrmStorage);
EXPECT_TRUE(
storage_dict->GetDictionaryWithoutPathExpansion(kTestOrigin, nullptr));
}
TEST_F(MediaDrmStorageImplTest, OnProvisioned_Twice) {
OnProvisioned();
SaveAndLoadPersistentSession("session_id", {1, 0}, "mime/type1");
// Provisioning again will clear everything associated with the origin.
OnProvisioned();
LoadPersistentSessionAndExpectFailure("session_id");
base::RunLoop().RunUntilIdle();
}
TEST_F(MediaDrmStorageImplTest, SaveSession_Unprovisioned) {
SavePersistentSession("session_id", {1, 0}, "mime/type", false);
base::RunLoop().RunUntilIdle();
}
TEST_F(MediaDrmStorageImplTest, SaveSession_SaveTwice) {
OnProvisioned();
SaveAndLoadPersistentSession("session_id", {1, 0}, "mime/type1");
SaveAndLoadPersistentSession("session_id", {2, 3}, "mime/type2");
base::RunLoop().RunUntilIdle();
}
TEST_F(MediaDrmStorageImplTest, SaveAndLoadSession_LoadTwice) {
OnProvisioned();
SaveAndLoadPersistentSession("session_id", {1, 0}, "mime/type");
LoadPersistentSession("session_id", {1, 0}, "mime/type");
base::RunLoop().RunUntilIdle();
}
TEST_F(MediaDrmStorageImplTest, SaveAndLoadSession_SpecialCharacters) {
OnProvisioned();
SaveAndLoadPersistentSession("session.id", {1, 0}, "mime.type");
SaveAndLoadPersistentSession("session/id", {1, 0}, "mime/type");
SaveAndLoadPersistentSession("session-id", {1, 0}, "mime-type");
SaveAndLoadPersistentSession("session_id", {1, 0}, "mime_type");
SaveAndLoadPersistentSession("session,id", {1, 0}, "mime,type");
base::RunLoop().RunUntilIdle();
}
TEST_F(MediaDrmStorageImplTest, LoadSession_Unprovisioned) {
LoadPersistentSessionAndExpectFailure("session_id");
base::RunLoop().RunUntilIdle();
}
TEST_F(MediaDrmStorageImplTest, RemoveSession_Success) {
OnProvisioned();
SaveAndLoadPersistentSession("session_id", {1, 0}, "mime/type");
RemovePersistentSession("session_id", true);
LoadPersistentSessionAndExpectFailure("session_id");
base::RunLoop().RunUntilIdle();
}
TEST_F(MediaDrmStorageImplTest, RemoveSession_InvalidSession) {
OnProvisioned();
SaveAndLoadPersistentSession("session_id", {1, 0}, "mime/type");
RemovePersistentSession("invalid_session_id", true);
// Can still load "session_id" session.
LoadPersistentSession("session_id", {1, 0}, "mime/type");
base::RunLoop().RunUntilIdle();
}
} // namespace cdm
...@@ -68,10 +68,6 @@ class MEDIA_EXPORT MediaDrmStorage { ...@@ -68,10 +68,6 @@ class MEDIA_EXPORT MediaDrmStorage {
LoadPersistentSessionCB load_persistent_session_cb) = 0; LoadPersistentSessionCB load_persistent_session_cb) = 0;
// Removes the persistent session info for |session_id| from the storage. // Removes the persistent session info for |session_id| from the storage.
// If the session for |session_id| exists in the storage, it is removed.
// Otherwise, this call is a no-op. In both cases, the result will be true.
// The result will be false on other unexpected errors, e.g. connection error
// to the storage backend.
virtual void RemovePersistentSession(const std::string& session_id, virtual void RemovePersistentSession(const std::string& session_id,
ResultCB result_cb) = 0; ResultCB result_cb) = 0;
......
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