2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-13 12:29:53 -06:00
|
|
|
RSpec.describe MetadataController do
|
2018-06-13 22:13:28 -05:00
|
|
|
describe "manifest.webmanifest" do
|
2019-05-01 08:44:45 -05:00
|
|
|
before { SiteIconManager.enable }
|
|
|
|
|
|
|
|
let(:upload) do
|
|
|
|
UploadCreator.new(file_from_fixtures("smallest.png"), "logo.png").create_for(
|
|
|
|
Discourse.system_user.id,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2016-02-13 12:29:53 -06:00
|
|
|
it "returns the right output" do
|
|
|
|
title = "MyApp"
|
|
|
|
SiteSetting.title = title
|
2019-05-01 08:44:45 -05:00
|
|
|
SiteSetting.manifest_icon = upload
|
2017-11-03 00:19:31 -05:00
|
|
|
|
2018-06-13 22:13:28 -05:00
|
|
|
get "/manifest.webmanifest"
|
2018-06-07 00:08:28 -05:00
|
|
|
expect(response.status).to eq(200)
|
2019-09-11 19:41:50 -05:00
|
|
|
expect(response.media_type).to eq("application/manifest+json")
|
2020-06-30 21:58:02 -05:00
|
|
|
expect(response.headers["Cache-Control"]).to eq("max-age=60, private")
|
|
|
|
|
2017-11-03 00:19:31 -05:00
|
|
|
manifest = JSON.parse(response.body)
|
|
|
|
|
|
|
|
expect(manifest["name"]).to eq(title)
|
2018-11-14 01:03:02 -06:00
|
|
|
|
|
|
|
expect(manifest["icons"].first["src"]).to eq(
|
2019-05-01 08:44:45 -05:00
|
|
|
UrlHelper.absolute(SiteSetting.site_manifest_icon_url),
|
2018-11-14 01:03:02 -06:00
|
|
|
)
|
2016-02-13 12:29:53 -06:00
|
|
|
end
|
2018-05-17 14:10:35 -05:00
|
|
|
|
|
|
|
it "can guess mime types" do
|
2019-05-01 08:44:45 -05:00
|
|
|
upload =
|
|
|
|
UploadCreator.new(file_from_fixtures("logo.jpg"), "logo.jpg").create_for(
|
|
|
|
Discourse.system_user.id,
|
|
|
|
)
|
2018-11-14 01:03:02 -06:00
|
|
|
|
2019-05-01 08:44:45 -05:00
|
|
|
SiteSetting.manifest_icon = upload
|
2018-06-13 22:13:28 -05:00
|
|
|
get "/manifest.webmanifest"
|
2018-11-14 01:03:02 -06:00
|
|
|
|
2018-06-07 00:08:28 -05:00
|
|
|
expect(response.status).to eq(200)
|
2018-05-17 14:10:35 -05:00
|
|
|
manifest = JSON.parse(response.body)
|
2018-05-17 16:43:22 -05:00
|
|
|
expect(manifest["icons"].first["type"]).to eq("image/jpeg")
|
2018-05-17 14:10:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "defaults to png" do
|
2019-05-01 08:44:45 -05:00
|
|
|
SiteSetting.manifest_icon = upload
|
2018-06-13 22:13:28 -05:00
|
|
|
get "/manifest.webmanifest"
|
2018-06-07 00:08:28 -05:00
|
|
|
expect(response.status).to eq(200)
|
2018-05-17 14:10:35 -05:00
|
|
|
manifest = JSON.parse(response.body)
|
|
|
|
expect(manifest["icons"].first["type"]).to eq("image/png")
|
|
|
|
end
|
2018-10-26 11:47:22 -05:00
|
|
|
|
|
|
|
it "defaults to display standalone for Android" do
|
|
|
|
get "/manifest.webmanifest",
|
|
|
|
params: {
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
"USER-AGENT" =>
|
|
|
|
"Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/67.0.3396.87 Mobile Safari/537.36",
|
|
|
|
}
|
|
|
|
manifest = JSON.parse(response.body)
|
|
|
|
expect(manifest["display"]).to eq("standalone")
|
|
|
|
end
|
|
|
|
|
2020-04-07 14:58:21 -05:00
|
|
|
it "defaults to display standalone for iPhone" do
|
2018-10-26 11:47:22 -05:00
|
|
|
get "/manifest.webmanifest",
|
|
|
|
params: {
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
"USER-AGENT" =>
|
|
|
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",
|
|
|
|
}
|
|
|
|
manifest = JSON.parse(response.body)
|
2020-04-07 14:58:21 -05:00
|
|
|
expect(manifest["display"]).to eq("standalone")
|
2018-10-26 11:47:22 -05:00
|
|
|
end
|
|
|
|
|
2020-04-07 14:58:21 -05:00
|
|
|
it "can be changed to display browser for iPhones using a site setting" do
|
|
|
|
SiteSetting.pwa_display_browser_regex = "iPhone"
|
2018-10-26 11:47:22 -05:00
|
|
|
|
|
|
|
get "/manifest.webmanifest",
|
|
|
|
params: {
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
"USER-AGENT" =>
|
|
|
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",
|
|
|
|
}
|
|
|
|
manifest = JSON.parse(response.body)
|
2020-04-07 14:58:21 -05:00
|
|
|
expect(manifest["display"]).to eq("browser")
|
2018-10-26 11:47:22 -05:00
|
|
|
end
|
|
|
|
|
2018-11-28 07:55:52 -06:00
|
|
|
it "uses the short_title if it is set" do
|
2020-02-04 11:46:33 -06:00
|
|
|
title = "FooBarBaz Forum"
|
|
|
|
SiteSetting.title = title
|
|
|
|
|
2018-11-28 07:55:52 -06:00
|
|
|
get "/manifest.webmanifest"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
manifest = JSON.parse(response.body)
|
2020-02-04 11:46:33 -06:00
|
|
|
expect(manifest["short_name"]).to eq("FooBarBaz")
|
2018-11-28 07:55:52 -06:00
|
|
|
|
|
|
|
SiteSetting.short_title = "foo"
|
|
|
|
|
|
|
|
get "/manifest.webmanifest"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
manifest = JSON.parse(response.body)
|
|
|
|
expect(manifest["short_name"]).to eq("foo")
|
|
|
|
end
|
2020-05-12 10:24:33 -05:00
|
|
|
|
|
|
|
it "contains valid shortcuts by default" do
|
|
|
|
get "/manifest.webmanifest"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
manifest = JSON.parse(response.body)
|
|
|
|
expect(manifest["shortcuts"].size).to be > 0
|
2022-02-01 12:26:58 -06:00
|
|
|
expect { URI.parse(manifest["shortcuts"][0]["url"]) }.not_to raise_error
|
2020-05-12 10:24:33 -05:00
|
|
|
end
|
2016-02-13 12:29:53 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "opensearch.xml" do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:upload)
|
2019-05-01 08:44:45 -05:00
|
|
|
|
2016-02-13 12:29:53 -06:00
|
|
|
it "returns the right output" do
|
|
|
|
title = "MyApp"
|
|
|
|
SiteSetting.title = title
|
2018-11-14 01:03:02 -06:00
|
|
|
SiteSetting.favicon = upload
|
2018-06-07 00:08:28 -05:00
|
|
|
get "/opensearch.xml"
|
2018-11-14 01:03:02 -06:00
|
|
|
|
2020-06-30 21:58:02 -05:00
|
|
|
expect(response.headers["Cache-Control"]).to eq("max-age=60, private")
|
|
|
|
|
2018-06-07 00:08:28 -05:00
|
|
|
expect(response.status).to eq(200)
|
2016-02-13 12:29:53 -06:00
|
|
|
expect(response.body).to include(title)
|
|
|
|
expect(response.body).to include("/search?q={searchTerms}")
|
|
|
|
expect(response.body).to include("image/png")
|
2018-11-14 01:03:02 -06:00
|
|
|
expect(response.body).to include(UrlHelper.absolute(upload.url))
|
2019-09-11 19:41:50 -05:00
|
|
|
expect(response.media_type).to eq("application/xml")
|
2016-02-13 12:29:53 -06:00
|
|
|
end
|
|
|
|
end
|
2019-08-27 13:05:37 -05:00
|
|
|
|
|
|
|
describe "#app_association_android" do
|
|
|
|
it "returns 404 by default" do
|
|
|
|
get "/.well-known/assetlinks.json"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the right output" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 13:50:55 -06:00
|
|
|
SiteSetting.app_association_android = <<~JSON
|
2019-08-27 13:05:37 -05:00
|
|
|
[{
|
|
|
|
"relation": ["delegate_permission/common.handle_all_urls"],
|
|
|
|
"target" : { "namespace": "android_app", "package_name": "com.example.app",
|
|
|
|
"sha256_cert_fingerprints": ["hash_of_app_certificate"] }
|
|
|
|
}]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 13:50:55 -06:00
|
|
|
JSON
|
2019-08-27 13:05:37 -05:00
|
|
|
get "/.well-known/assetlinks.json"
|
|
|
|
|
2020-06-30 21:58:02 -05:00
|
|
|
expect(response.headers["Cache-Control"]).to eq("max-age=60, private")
|
|
|
|
|
2019-08-27 13:05:37 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include("hash_of_app_certificate")
|
|
|
|
expect(response.body).to include("com.example.app")
|
2019-09-11 19:41:50 -05:00
|
|
|
expect(response.media_type).to eq("application/json")
|
2019-08-27 13:05:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#app_association_ios" do
|
|
|
|
it "returns 404 by default" do
|
|
|
|
get "/apple-app-site-association"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the right output" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 13:50:55 -06:00
|
|
|
SiteSetting.app_association_ios = <<~JSON
|
2019-08-27 13:05:37 -05:00
|
|
|
{
|
|
|
|
"applinks": {
|
|
|
|
"apps": []
|
|
|
|
}
|
|
|
|
}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 13:50:55 -06:00
|
|
|
JSON
|
2019-08-27 13:05:37 -05:00
|
|
|
get "/apple-app-site-association"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include("applinks")
|
2019-09-11 19:41:50 -05:00
|
|
|
expect(response.media_type).to eq("application/json")
|
2020-06-30 21:58:02 -05:00
|
|
|
expect(response.headers["Cache-Control"]).to eq("max-age=60, private")
|
2019-08-27 13:05:37 -05:00
|
|
|
|
|
|
|
get "/apple-app-site-association.json"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
2016-02-13 12:29:53 -06:00
|
|
|
end
|