1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
// Copyright 2016 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 "chrome/browser/chromeos/extensions/gfx_utils.h"
#include "base/macros.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/arc/arc_app_test.h"
#include "chrome/test/base/testing_profile.h"
#include "components/arc/test/fake_app_instance.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
namespace extensions {
namespace {
constexpr char kGmailArcPackage[] = "com.google.android.gm";
constexpr char kGmailArcActivity[] =
"com.google.android.gm.ConversationListActivityGmail";
constexpr char kGmailExtensionId1[] = "pjkljhegncpnkpknbcohdijeoejaedia";
constexpr char kGmailExtensionId2[] = "bjdhhokmhgelphffoafoejjmlfblpdha";
constexpr char kDriveArcPackage[] = "com.google.android.apps.docs";
constexpr char kKeepExtensionId[] = "hmjkmjkepdijhoojdojkdfohbdgmmhki";
} // namespace
class DualBadgeMapTest : public ExtensionServiceTestBase {
public:
DualBadgeMapTest() {}
~DualBadgeMapTest() override { profile_.reset(); }
void SetUp() override {
extensions::ExtensionServiceTestBase::SetUp();
InitializeEmptyExtensionService();
arc_test_.SetUp(profile_.get());
}
void TearDown() override { arc_test_.TearDown(); }
Profile* profile() { return profile_.get(); }
protected:
arc::mojom::ArcPackageInfo CreateArcPackage(const std::string& package_name) {
arc::mojom::ArcPackageInfo package;
package.package_name = package_name;
package.package_version = 1;
package.last_backup_android_id = 1;
package.last_backup_time = 1;
package.sync = false;
return package;
}
void AddArcPackage(const arc::mojom::ArcPackageInfo& package) {
arc_test_.AddPackage(package);
arc_test_.app_instance()->SendPackageAdded(package);
}
void RemoveArcPackage(const arc::mojom::ArcPackageInfo& package) {
arc_test_.RemovePackage(package);
arc_test_.app_instance()->SendPackageUninstalled(package.package_name);
}
arc::mojom::AppInfo CreateArcApp(const std::string& name,
const std::string& package,
const std::string& activity) {
arc::mojom::AppInfo info;
info.name = name;
info.package_name = package;
info.activity = activity;
info.sticky = false;
info.notifications_enabled = false;
info.orientation_lock = arc::mojom::OrientationLock::NONE;
return info;
}
void AddArcApp(const arc::mojom::AppInfo& app) {
arc_test_.app_instance()->SendAppAdded(app);
}
scoped_refptr<Extension> CreateExtension(const std::string& id) {
return ExtensionBuilder()
.SetManifest(DictionaryBuilder()
.Set("name", "test")
.Set("version", "0.1")
.Build())
.SetID(id)
.Build();
}
void AddExtension(const Extension* extension) {
service()->AddExtension(extension);
}
void RemoveExtension(const Extension* extension) {
service()->UninstallExtension(extension->id(),
extensions::UNINSTALL_REASON_FOR_TESTING,
base::Bind(&base::DoNothing), NULL);
}
private:
ArcAppTest arc_test_;
DISALLOW_COPY_AND_ASSIGN(DualBadgeMapTest);
};
TEST_F(DualBadgeMapTest, ExtensionToArcAppMapTest) {
// Install two Gmail extension apps.
AddExtension(CreateExtension(kGmailExtensionId1).get());
AddExtension(CreateExtension(kGmailExtensionId2).get());
EXPECT_FALSE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId1));
EXPECT_FALSE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId2));
// Install Gmail Playstore app.
const arc::mojom::ArcPackageInfo app_info =
CreateArcPackage(kGmailArcPackage);
AddArcPackage(app_info);
EXPECT_FALSE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId1));
EXPECT_FALSE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId2));
AddArcApp(CreateArcApp("gmail", kGmailArcPackage, kGmailArcActivity));
EXPECT_TRUE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId1));
EXPECT_TRUE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId2));
RemoveArcPackage(app_info);
EXPECT_FALSE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId1));
EXPECT_FALSE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId2));
// Install an unrelated Playstore app.
AddArcPackage(CreateArcPackage(kDriveArcPackage));
EXPECT_FALSE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId1));
EXPECT_FALSE(extensions::util::HasEquivalentInstalledArcApp(
profile(), kGmailExtensionId2));
}
TEST_F(DualBadgeMapTest, ArcAppToExtensionMapTest) {
// Install Gmail Playstore app.
AddArcPackage(CreateArcPackage(kGmailArcPackage));
AddArcApp(CreateArcApp("gmail", kGmailArcPackage, kGmailArcActivity));
std::vector<std::string> extension_ids =
extensions::util::GetEquivalentInstalledExtensions(profile(),
kGmailArcPackage);
EXPECT_TRUE(0 == extension_ids.size());
// Install Gmail extension app.
scoped_refptr<Extension> extension1 = CreateExtension(kGmailExtensionId1);
AddExtension(extension1.get());
extension_ids = extensions::util::GetEquivalentInstalledExtensions(
profile(), kGmailArcPackage);
EXPECT_TRUE(1 == extension_ids.size());
EXPECT_TRUE(std::find(extension_ids.begin(), extension_ids.end(),
kGmailExtensionId1) != extension_ids.end());
// Install another Gmail extension app.
scoped_refptr<Extension> extension2 = CreateExtension(kGmailExtensionId2);
AddExtension(extension2.get());
extension_ids = extensions::util::GetEquivalentInstalledExtensions(
profile(), kGmailArcPackage);
EXPECT_TRUE(2 == extension_ids.size());
EXPECT_TRUE(std::find(extension_ids.begin(), extension_ids.end(),
kGmailExtensionId1) != extension_ids.end());
EXPECT_TRUE(std::find(extension_ids.begin(), extension_ids.end(),
kGmailExtensionId2) != extension_ids.end());
RemoveExtension(extension1.get());
extension_ids = extensions::util::GetEquivalentInstalledExtensions(
profile(), kGmailArcPackage);
EXPECT_TRUE(1 == extension_ids.size());
EXPECT_FALSE(std::find(extension_ids.begin(), extension_ids.end(),
kGmailExtensionId1) != extension_ids.end());
EXPECT_TRUE(std::find(extension_ids.begin(), extension_ids.end(),
kGmailExtensionId2) != extension_ids.end());
RemoveExtension(extension2.get());
extension_ids = extensions::util::GetEquivalentInstalledExtensions(
profile(), kGmailArcPackage);
EXPECT_TRUE(0 == extension_ids.size());
// Install an unrelated Google Keep extension app.
scoped_refptr<Extension> extension = CreateExtension(kKeepExtensionId);
AddExtension(extension.get());
extension_ids = extensions::util::GetEquivalentInstalledExtensions(
profile(), kGmailArcPackage);
EXPECT_TRUE(0 == extension_ids.size());
}
} // namespace extensions
|