File: app_modal_dialog_manager_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 (112 lines) | stat: -rw-r--r-- 4,074 bytes parent folder | download | duplicates (11)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/javascript_dialogs/app_modal_dialog_manager.h"

#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/origin.h"

namespace javascript_dialogs {

TEST(AppModalDialogManagerTest, GetTitle) {
  struct Case {
    // The name of the test case.
    const char* case_name;

    // The URL of the main frame of the page.
    const char* main_frame_url;

    // Whether the main frame is alerting.
    bool is_main_frame;

    // If `is_main_frame` is false, the URL of the alerting frame of the page.
    const char* alerting_frame_url;

    // The expected title for the alert.
    const char* expected;
  } cases[] = {
      // Standard main frame alert.
      {"standard", "http://foo.com/", true, "", "foo.com says"},

      // Subframe alert from the same origin.
      {"subframe same origin", "http://foo.com/1", false, "http://foo.com/2",
       "foo.com says"},
      // Subframe alert from a different origin.
      {"subframe different origin", "http://foo.com/", false, "http://bar.com/",
       "An embedded page at bar.com says"},

      // file:
      // - main frame:
      {"file main frame", "file:///path/to/page.html", true, "",
       "This page says"},
      // - subframe:
      {"file subframe", "http://foo.com/", false, "file:///path/to/page.html",
       "An embedded page on this page says"},

      // data:
      // /!\ NOTE that this is for data URLs entered directly in the omnibox.
      // For pages that generate frames with data URLs, see the browsertest.
      // - main frame:
      {"data main frame", "data:blahblah", true, "", "This page says"},
      // - subframe:
      {"data subframe", "http://foo.com/", false, "data:blahblah",
       "An embedded page on this page says"},

      // javascript:
      // /!\ NOTE that this is for javascript URLs entered directly in the
      // omnibox. For pages that generate frames with javascript URLs, see the
      // browsertest.
      // - main frame:
      {"javascript main frame", "javascript:abc", true, "", "This page says"},
      // - subframe:
      {"javascript subframe", "http://foo.com/", false, "javascript:abc",
       "An embedded page on this page says"},

      // about:
      // /!\ NOTE that this is for about:blank URLs entered directly in the
      // omnibox. For pages that generate frames with about:blank URLs, see the
      // browsertest.
      // - main frame:
      {"about main frame", "about:blank", true, "", "This page says"},
      // - subframe:
      {"about subframe", "http://foo.com/", false, "about:blank",
       "An embedded page on this page says"},

      // blob:
      // - main frame:
      {"blob main frame",
       "blob:http://foo.com/66666666-6666-6666-6666-666666666666", true, "",
       "foo.com says"},
      // - subframe:
      {"blob subframe", "http://bar.com/", false,
       "blob:http://foo.com/66666666-6666-6666-6666-666666666666",
       "An embedded page at foo.com says"},

      // filesystem:
      // - main frame:
      {"filesystem main frame", "filesystem:http://foo.com/bar.html", true, "",
       "foo.com says"},
      // - subframe:
      {"filesystem subframe", "http://bar.com/", false,
       "filesystem:http://foo.com/bar.html",
       "An embedded page at foo.com says"},
  };

  for (const auto& test_case : cases) {
    SCOPED_TRACE(test_case.case_name);
    url::Origin main_frame_origin =
        url::Origin::Create(GURL(test_case.main_frame_url));
    url::Origin alerting_frame_origin =
        test_case.is_main_frame
            ? main_frame_origin
            : url::Origin::Create(GURL(test_case.alerting_frame_url));
    std::u16string result = AppModalDialogManager::GetSiteFrameTitle(
        main_frame_origin, alerting_frame_origin);
    EXPECT_EQ(test_case.expected, base::UTF16ToUTF8(result));
  }
}

}  // namespace javascript_dialogs