File: extension_manifests_launch_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (115 lines) | stat: -rw-r--r-- 5,540 bytes parent folder | download | duplicates (6)
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
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
#include "components/services/app_service/public/cpp/app_launch_util.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace extensions {

namespace errors = manifest_errors;
namespace keys = manifest_keys;

using AppLaunchManifestTest = ChromeManifestTest;

TEST_F(AppLaunchManifestTest, AppLaunchContainer) {
  scoped_refptr<Extension> extension = LoadAndExpectSuccess("launch_tab.json");
  EXPECT_EQ(apps::LaunchContainer::kLaunchContainerTab,
            AppLaunchInfo::GetLaunchContainer(extension.get()));

  extension = LoadAndExpectSuccess("launch_panel.json");
  EXPECT_EQ(apps::LaunchContainer::kLaunchContainerPanelDeprecated,
            AppLaunchInfo::GetLaunchContainer(extension.get()));

  extension = LoadAndExpectSuccess("launch_default.json");
  EXPECT_EQ(apps::LaunchContainer::kLaunchContainerTab,
            AppLaunchInfo::GetLaunchContainer(extension.get()));

  extension = LoadAndExpectSuccess("launch_width.json");
  EXPECT_EQ(640, AppLaunchInfo::GetLaunchWidth(extension.get()));

  extension = LoadAndExpectSuccess("launch_height.json");
  EXPECT_EQ(480, AppLaunchInfo::GetLaunchHeight(extension.get()));

  const Testcase testcases[] = {
      Testcase("launch_window.json", errors::kInvalidLaunchContainer),
      Testcase("launch_container_invalid_type.json",
               errors::kInvalidLaunchContainer),
      Testcase("launch_container_invalid_value.json",
               errors::kInvalidLaunchContainer),
      Testcase("launch_container_without_launch_url.json",
               errors::kLaunchURLRequired),
      Testcase("launch_width_invalid.json",
               ErrorUtils::FormatErrorMessage(
                   errors::kInvalidLaunchValueContainer, keys::kLaunchWidth)),
      Testcase("launch_width_negative.json",
               ErrorUtils::FormatErrorMessage(errors::kInvalidLaunchValue,
                                              keys::kLaunchWidth)),
      Testcase("launch_height_invalid.json",
               ErrorUtils::FormatErrorMessage(
                   errors::kInvalidLaunchValueContainer, keys::kLaunchHeight)),
      Testcase("launch_height_negative.json",
               ErrorUtils::FormatErrorMessage(errors::kInvalidLaunchValue,
                                              keys::kLaunchHeight))};
  RunTestcases(testcases, EXPECT_TYPE_ERROR);
}

TEST_F(AppLaunchManifestTest, AppLaunchURL) {
  const Testcase testcases[] = {
      Testcase("launch_path_and_url.json",
               errors::kLaunchPathAndURLAreExclusive),
      Testcase("launch_path_and_extent.json",
               errors::kLaunchPathAndExtentAreExclusive),
      Testcase("launch_path_invalid_type.json",
               ErrorUtils::FormatErrorMessage(errors::kInvalidLaunchValue,
                                              keys::kLaunchLocalPath)),
      Testcase("launch_path_invalid_value.json",
               ErrorUtils::FormatErrorMessage(errors::kInvalidLaunchValue,
                                              keys::kLaunchLocalPath)),
      Testcase("launch_path_invalid_localized.json",
               ErrorUtils::FormatErrorMessage(errors::kInvalidLaunchValue,
                                              keys::kLaunchLocalPath)),
      Testcase("launch_url_invalid_type_1.json",
               ErrorUtils::FormatErrorMessage(errors::kInvalidLaunchValue,
                                              keys::kLaunchWebURL)),
      Testcase("launch_url_invalid_type_2.json",
               ErrorUtils::FormatErrorMessage(errors::kInvalidLaunchValue,
                                              keys::kLaunchWebURL)),
      Testcase("launch_url_invalid_type_3.json",
               ErrorUtils::FormatErrorMessage(errors::kInvalidLaunchValue,
                                              keys::kLaunchWebURL)),
      Testcase("launch_url_invalid_localized.json",
               ErrorUtils::FormatErrorMessage(errors::kInvalidLaunchValue,
                                              keys::kLaunchWebURL))};
  RunTestcases(testcases, EXPECT_TYPE_ERROR);

  scoped_refptr<Extension> extension =
      LoadAndExpectSuccess("launch_local_path.json");
  EXPECT_EQ(extension->url().spec() + "launch.html",
            AppLaunchInfo::GetFullLaunchURL(extension.get()).spec());

  extension = LoadAndExpectSuccess("launch_local_path_localized.json");
  EXPECT_EQ(extension->url().spec() + "launch.html",
            AppLaunchInfo::GetFullLaunchURL(extension.get()).spec());

  LoadAndExpectError("launch_web_url_relative.json",
                     ErrorUtils::FormatErrorMessage(
                         errors::kInvalidLaunchValue,
                         keys::kLaunchWebURL));

  extension = LoadAndExpectSuccess("launch_web_url_absolute.json");
  EXPECT_EQ(GURL("http://www.google.com/launch.html"),
            AppLaunchInfo::GetFullLaunchURL(extension.get()));
  extension = LoadAndExpectSuccess("launch_web_url_localized.json");
  EXPECT_EQ(GURL("http://www.google.com/launch.html"),
            AppLaunchInfo::GetFullLaunchURL(extension.get()));
}

}  // namespace extensions