blob: 4b455ce31681ce39a2244a703237c96578883384 [file] [log] [blame]
// 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/app_modal/javascript_dialog_manager.h"
// #include <string>
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace app_modal {
TEST(JavaScriptDialogManagerTest, GetTitle) {
struct Case {
const char* parent_url;
const char* alerting_url;
const char* expected;
const char* expected_android;
} cases[] = {
// Standard main frame alert.
{"http://foo.com/", "http://foo.com/", "foo.com says", "foo.com says"},
// Subframe alert from the same origin.
{"http://foo.com/1", "http://foo.com/2", "foo.com says", "foo.com says"},
// Subframe alert from a different origin.
{"http://foo.com/", "http://bar.com/", "An embedded page at bar.com says",
"An embedded page at bar.com says"},
// file:
// - main frame:
{"file:///path/to/page.html", "file:///path/to/page.html",
"This page says", "This page says"},
// - subframe:
{"http://foo.com/", "file:///path/to/page.html",
"An embedded page on this page says",
"An embedded page on this page says"},
// ftp:
// - main frame:
{"ftp://foo.com/path/to/page.html", "ftp://foo.com/path/to/page.html",
"foo.com says", "ftp://foo.com says"},
// - subframe:
{"http://foo.com/", "ftp://foo.com/path/to/page.html",
"An embedded page at foo.com says",
"An embedded page at ftp://foo.com says"},
// data:
// - main frame:
{"data:blahblah", "data:blahblah", "This page says", "This page says"},
// - subframe:
{"http://foo.com/", "data:blahblah", "An embedded page on this page says",
"An embedded page on this page says"},
// javascript:
// - main frame:
{"javascript:abc", "javascript:abc", "This page says", "This page says"},
// - subframe:
{"http://foo.com/", "javascript:abc",
"An embedded page on this page says",
"An embedded page on this page says"},
// about:
// - main frame:
{"about:blank", "about:blank", "This page says", "This page says"},
// - subframe:
{"http://foo.com/", "about:blank", "An embedded page on this page says",
"An embedded page on this page says"},
// blob:
// - main frame:
{"blob:http://foo.com/66666666-6666-6666-6666-666666666666",
"blob:http://foo.com/66666666-6666-6666-6666-666666666666",
"foo.com says", "foo.com says"},
// - subframe:
{"http://bar.com/",
"blob:http://foo.com/66666666-6666-6666-6666-666666666666",
"An embedded page at foo.com says", "An embedded page at foo.com says"},
// filesystem:
// - main frame:
{"filesystem:http://foo.com/bar.html",
"filesystem:http://foo.com/bar.html", "foo.com says", "foo.com says"},
// - subframe:
{"http://bar.com/", "filesystem:http://foo.com/bar.html",
"An embedded page at foo.com says", "An embedded page at foo.com says"},
};
for (const auto& test_case : cases) {
base::string16 result = JavaScriptDialogManager::GetTitleImpl(
GURL(test_case.parent_url), GURL(test_case.alerting_url));
#if defined(OS_ANDROID)
EXPECT_EQ(test_case.expected_android, base::UTF16ToUTF8(result));
#else
EXPECT_EQ(test_case.expected, base::UTF16ToUTF8(result));
#endif
}
}
} // namespace app_modal