Resolve presumit error

Resolve unit test around PlaylistChangeParams::Type

Remove unnecessary null check

Update year in license section
This commit is contained in:
deeppandya
2023-03-26 15:25:30 +05:30
parent 5a050410ae
commit ca9a4d4269
5 changed files with 40 additions and 44 deletions
@@ -433,10 +433,7 @@ public class PlaylistHostActivity extends AsyncInitializationActivity
playlistEvent = PlaylistEventEnum.kNone;
break;
}
if (mPlaylistViewModel != null) {
mPlaylistViewModel.updatePlaylistEvent(
new PlaylistEventModel(playlistEvent, playlistId));
}
mPlaylistViewModel.updatePlaylistEvent(new PlaylistEventModel(playlistEvent, playlistId));
}
@Override
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--* Copyright (c) 2022 The Brave Authors. All rights reserved.
<!--* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 The Brave Authors. All rights reserved.
<!-- Copyright (c) 2023 The Brave Authors. All rights reserved.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/. -->
@@ -18,6 +18,7 @@
#include "brave/components/playlist/browser/pref_names.h"
#include "brave/components/playlist/browser/type_converter.h"
#include "brave/components/playlist/common/features.h"
#include "brave/components/playlist/common/mojom/playlist.mojom.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/test/base/testing_profile.h"
@@ -272,14 +273,14 @@ TEST_F(PlaylistServiceUnitTest, CreatePlaylistItem) {
int expected_call_count = 3;
testing::NiceMock<MockObserver> observer;
auto on_event = [&]() { expected_call_count--; };
auto expected_arg = PlaylistChangeParams(
PlaylistChangeParams::Type::kItemThumbnailReady, id);
auto expected_arg =
PlaylistChangeParams(mojom::PlaylistEvent::kItemThumbnailReady, id);
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemAdded;
expected_arg.change_type = mojom::PlaylistEvent::kItemAdded;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemCached;
expected_arg.change_type = mojom::PlaylistEvent::kItemCached;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
using testing::_;
@@ -313,14 +314,14 @@ TEST_F(PlaylistServiceUnitTest, ThumbnailFailed) {
int expected_call_count = 3;
testing::NiceMock<MockObserver> observer;
auto on_event = [&]() { expected_call_count--; };
auto expected_arg = PlaylistChangeParams(
PlaylistChangeParams::Type::kItemThumbnailFailed, id);
auto expected_arg =
PlaylistChangeParams(mojom::PlaylistEvent::kItemThumbnailFailed, id);
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemAdded;
expected_arg.change_type = mojom::PlaylistEvent::kItemAdded;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemCached;
expected_arg.change_type = mojom::PlaylistEvent::kItemCached;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
@@ -354,14 +355,14 @@ TEST_F(PlaylistServiceUnitTest, MediaDownloadFailed) {
testing::NiceMock<MockObserver> observer;
auto on_event = [&]() { expected_call_count--; };
auto expected_arg =
PlaylistChangeParams(PlaylistChangeParams::Type::kItemAdded, id);
PlaylistChangeParams(mojom::PlaylistEvent::kItemAdded, id);
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemAborted;
expected_arg.change_type = mojom::PlaylistEvent::kItemAborted;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemThumbnailReady;
expected_arg.change_type = mojom::PlaylistEvent::kItemThumbnailReady;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.Times(testing::AtMost(1));
@@ -398,13 +399,13 @@ TEST_F(PlaylistServiceUnitTest, MediaRecoverTest) {
testing::NiceMock<MockObserver> observer;
auto on_event = [&]() { expected_call_count--; };
auto expected_arg =
PlaylistChangeParams(PlaylistChangeParams::Type::kItemAdded, id);
PlaylistChangeParams(mojom::PlaylistEvent::kItemAdded, id);
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemAborted;
expected_arg.change_type = mojom::PlaylistEvent::kItemAborted;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemThumbnailReady;
expected_arg.change_type = mojom::PlaylistEvent::kItemThumbnailReady;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.Times(testing::AtMost(1));
@@ -432,10 +433,10 @@ TEST_F(PlaylistServiceUnitTest, MediaRecoverTest) {
bool called = false;
testing::NiceMock<MockObserver> observer;
auto expected_arg =
PlaylistChangeParams(PlaylistChangeParams::Type::kItemAborted, id);
PlaylistChangeParams(mojom::PlaylistEvent::kItemAborted, id);
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce([&]() { called = true; });
expected_arg.change_type = PlaylistChangeParams::Type::kItemThumbnailReady;
expected_arg.change_type = mojom::PlaylistEvent::kItemThumbnailReady;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.Times(testing::AtMost(1));
@@ -455,11 +456,11 @@ TEST_F(PlaylistServiceUnitTest, MediaRecoverTest) {
bool called = false;
testing::NiceMock<MockObserver> observer;
auto expected_arg =
PlaylistChangeParams(PlaylistChangeParams::Type::kItemCached, id);
PlaylistChangeParams(mojom::PlaylistEvent::kItemCached, id);
EXPECT_CALL(observer,
OnPlaylistStatusChanged(PlaylistChangeParams(expected_arg)))
.WillOnce([&]() { called = true; });
expected_arg.change_type = PlaylistChangeParams::Type::kItemThumbnailReady;
expected_arg.change_type = mojom::PlaylistEvent::kItemThumbnailReady;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.Times(testing::AtMost(1));
@@ -496,13 +497,13 @@ TEST_F(PlaylistServiceUnitTest, DeleteItem) {
testing::NiceMock<MockObserver> observer;
auto on_event = [&]() { expected_call_count--; };
auto expected_arg =
PlaylistChangeParams(PlaylistChangeParams::Type::kItemAdded, id);
PlaylistChangeParams(mojom::PlaylistEvent::kItemAdded, id);
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemCached;
expected_arg.change_type = mojom::PlaylistEvent::kItemCached;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemThumbnailReady;
expected_arg.change_type = mojom::PlaylistEvent::kItemThumbnailReady;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.Times(testing::AtMost(1));
@@ -529,9 +530,8 @@ TEST_F(PlaylistServiceUnitTest, DeleteItem) {
auto id = items.front()->id;
bool called = false;
testing::NiceMock<MockObserver> observer;
EXPECT_CALL(observer,
OnPlaylistStatusChanged(PlaylistChangeParams(
PlaylistChangeParams::Type::kItemDeleted, id)))
EXPECT_CALL(observer, OnPlaylistStatusChanged(PlaylistChangeParams(
mojom::PlaylistEvent::kItemDeleted, id)))
.WillOnce([&]() { called = true; });
service->AddObserverForTest(&observer);
@@ -551,7 +551,7 @@ TEST_F(PlaylistServiceUnitTest, DeleteItem) {
bool called = false;
testing::NiceMock<MockObserver> observer;
EXPECT_CALL(observer, OnPlaylistStatusChanged(PlaylistChangeParams(
PlaylistChangeParams::Type::kAllDeleted, "")))
mojom::PlaylistEvent::kAllDeleted, "")))
.WillOnce([&]() { called = true; });
service->AddObserverForTest(&observer);
@@ -586,7 +586,7 @@ TEST_F(PlaylistServiceUnitTest, CreateAndRemovePlaylist) {
testing::NiceMock<MockObserver> observer;
EXPECT_CALL(observer, OnPlaylistStatusChanged(testing::Field(
&PlaylistChangeParams::change_type,
PlaylistChangeParams::Type::kListCreated)))
mojom::PlaylistEvent::kListCreated)))
.WillOnce([&]() { called = true; });
service->AddObserverForTest(&observer);
@@ -617,7 +617,7 @@ TEST_F(PlaylistServiceUnitTest, CreateAndRemovePlaylist) {
testing::NiceMock<MockObserver> observer;
EXPECT_CALL(observer, OnPlaylistStatusChanged(testing::Field(
&PlaylistChangeParams::change_type,
PlaylistChangeParams::Type::kListRemoved)))
mojom::PlaylistEvent::kListRemoved)))
.WillOnce([&]() { called = true; });
service->AddObserverForTest(&observer);
@@ -647,13 +647,13 @@ TEST_F(PlaylistServiceUnitTest, RemoveAndRestoreLocalData) {
testing::NiceMock<MockObserver> observer;
auto on_event = [&]() { expected_call_count--; };
auto expected_arg =
PlaylistChangeParams(PlaylistChangeParams::Type::kItemAdded, id);
PlaylistChangeParams(mojom::PlaylistEvent::kItemAdded, id);
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemCached;
expected_arg.change_type = mojom::PlaylistEvent::kItemCached;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemThumbnailReady;
expected_arg.change_type = mojom::PlaylistEvent::kItemThumbnailReady;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.Times(testing::AtMost(1));
@@ -942,15 +942,15 @@ TEST_F(PlaylistServiceUnitTest, CachingBehavior) {
int expected_call_count = 3 - (should_cache ? 0 : 1);
testing::NiceMock<MockObserver> observer;
auto on_event = [&]() { expected_call_count--; };
auto expected_arg = PlaylistChangeParams(
PlaylistChangeParams::Type::kItemThumbnailReady, id);
auto expected_arg =
PlaylistChangeParams(mojom::PlaylistEvent::kItemThumbnailReady, id);
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemAdded;
expected_arg.change_type = mojom::PlaylistEvent::kItemAdded;
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
expected_arg.change_type = PlaylistChangeParams::Type::kItemCached;
expected_arg.change_type = mojom::PlaylistEvent::kItemCached;
if (should_cache) {
EXPECT_CALL(observer, OnPlaylistStatusChanged(expected_arg))
.WillOnce(on_event);
@@ -1024,9 +1024,8 @@ TEST_F(PlaylistServiceUnitTest, UpdateItem) {
}));
testing::NiceMock<MockObserver> observer;
EXPECT_CALL(observer,
OnPlaylistStatusChanged(PlaylistChangeParams(
PlaylistChangeParams::Type::kItemUpdated, item.id)));
EXPECT_CALL(observer, OnPlaylistStatusChanged(PlaylistChangeParams(
mojom::PlaylistEvent::kItemUpdated, item.id)));
playlist_service()->AddObserverForTest(&observer);
item.name = "new name";
@@ -114,7 +114,7 @@ interface PlaylistService {
// Removes all stored data and resets preferences to default values.
ResetAll();
RenamePlaylist(string playlist_id, string playlist_name)
RenamePlaylist(string playlist_id, string playlist_name)
=> (Playlist updated_playlist);
AddObserver(pending_remote<PlaylistServiceObserver> observer);