Commit 2a4f1b2d authored by Josh Simmons's avatar Josh Simmons Committed by Commit Bot

Add MIME type checks to existing browser tests.

Bug 1067499 requires the addition of individual browser tests to
validate the MIME type detected and reported by Quick View for all
file extensions known to Files.app. This CL is the first of many and
adds MIME type checks for file extensions with existing tests.

It also adds a new test that highlights the quirks of the file content
sniffing used by the Media Gallery API (the underlying implementation
used by Quick View to determine and report MIME type in the right-hand
metadata information box).

Subsequent CLs will split out MIME type testing from some of the current
tests (where it is overloaded in the test of a wider feature) and add
new tests for currently untested file extensions.

Bug: 1067499
Change-Id: I08fb9926ac3aa734f95cc5cc04afa1c241300cc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2141563Reviewed-by: default avatarAlex Danilo <adanilo@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Commit-Queue: Josh Simmons <simmonsjosh@google.com>
Cr-Commit-Position: refs/heads/master@{#757756}
parent 88567253
...@@ -498,6 +498,7 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P( ...@@ -498,6 +498,7 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P(
TestCase("openQuickViewKeyboardUpDownChangesView"), TestCase("openQuickViewKeyboardUpDownChangesView"),
TestCase("openQuickViewKeyboardLeftRightChangesView"), TestCase("openQuickViewKeyboardLeftRightChangesView"),
TestCase("openQuickViewSniffedText"), TestCase("openQuickViewSniffedText"),
TestCase("openQuickViewTextFileWithUnknownMimeType"),
TestCase("openQuickViewScrollText"), TestCase("openQuickViewScrollText"),
TestCase("openQuickViewScrollHtml"), TestCase("openQuickViewScrollHtml"),
TestCase("openQuickViewMhtml"), TestCase("openQuickViewMhtml"),
......
...@@ -305,7 +305,12 @@ ...@@ -305,7 +305,12 @@
// Open the file in Quick View. // Open the file in Quick View.
await openQuickView(appId, ENTRIES.hello.nameText); await openQuickView(appId, ENTRIES.hello.nameText);
// Check: the correct mimeType should be displayed. // Check: the correct mimeType should be displayed (note: MIME type
// identification differs depending on the metadata provider for the
// underlying volume. Here, it is reported as text/plain for ENTRIES.hello,
// because the file is on Drive, later (see
// openQuickViewTextFileWithUnknownMimeType) it is not reported because the
// file is on the local filesystem).
const mimeType = await getQuickViewMetadataBoxField(appId, 'Type'); const mimeType = await getQuickViewMetadataBoxField(appId, 'Type');
chrome.test.assertEq('text/plain', mimeType); chrome.test.assertEq('text/plain', mimeType);
}; };
...@@ -523,8 +528,8 @@ ...@@ -523,8 +528,8 @@
}; };
/** /**
* Tests opening Quick View with a document identified as text from file * Tests opening Quick View with a local text document identified as text from
* sniffing because it has no filename extension. * file sniffing (the first word of the file is "From ", note trailing space).
*/ */
testcase.openQuickViewSniffedText = async () => { testcase.openQuickViewSniffedText = async () => {
const caller = getCaller(); const caller = getCaller();
...@@ -563,6 +568,51 @@ ...@@ -563,6 +568,51 @@
chrome.test.assertEq('text/plain', mimeType); chrome.test.assertEq('text/plain', mimeType);
}; };
/**
* Tests opening Quick View with a local text document whose MIME type cannot
* be identified by MIME type sniffing.
*/
testcase.openQuickViewTextFileWithUnknownMimeType = async () => {
const caller = getCaller();
/**
* The text <webview> resides in the #quick-view shadow DOM, as a child of
* the #dialog element.
*/
const webView = ['#quick-view', '#dialog[open] webview.text-content'];
// Open Files app on Downloads containing ENTRIES.hello.
const appId =
await setupAndWaitUntilReady(RootPath.DOWNLOADS, [ENTRIES.hello], []);
// Open the file in Quick View.
await openQuickView(appId, ENTRIES.hello.nameText);
// Wait for the Quick View <webview> to load and display its content.
function checkWebViewTextLoaded(elements) {
let haveElements = Array.isArray(elements) && elements.length === 1;
if (haveElements) {
haveElements = elements[0].styles.display.includes('block');
}
if (!haveElements || !elements[0].attributes.src) {
return pending(caller, 'Waiting for <webview> to load.');
}
return;
}
await repeatUntil(async () => {
return checkWebViewTextLoaded(await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [webView, ['display']]));
});
// Check: no mimeType information is displayed. Note that there are multiple
// levels of shadow DOM present in this query.
const mimeTypeQuery = [
'#quick-view', '#dialog[open] files-metadata-box[metadata~="mime"]',
'files-metadata-entry[key="Type"]', '#box[hidden]'
];
await remoteCall.waitForElement(appId, mimeTypeQuery);
};
/** /**
* Tests opening Quick View and scrolling its <webview> which contains a tall * Tests opening Quick View and scrolling its <webview> which contains a tall
* text document. * text document.
...@@ -680,6 +730,10 @@ ...@@ -680,6 +730,10 @@
// Check: the <webview> embed type should be PDF mime type. // Check: the <webview> embed type should be PDF mime type.
chrome.test.assertEq('application/pdf', type); chrome.test.assertEq('application/pdf', type);
// Check: the correct mimeType should be displayed.
const mimeType = await getQuickViewMetadataBoxField(appId, 'Type');
chrome.test.assertEq('application/pdf', mimeType);
}; };
/** /**
...@@ -759,6 +813,10 @@ ...@@ -759,6 +813,10 @@
return checkWebViewTextLoaded(await remoteCall.callRemoteTestUtil( return checkWebViewTextLoaded(await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [webView, ['display']])); 'deepQueryAllElements', appId, [webView, ['display']]));
}); });
// Check: the correct mimeType should be displayed.
const mimeType = await getQuickViewMetadataBoxField(appId, 'Type');
chrome.test.assertEq('text/plain', mimeType);
}; };
/** /**
...@@ -825,6 +883,14 @@ ...@@ -825,6 +883,14 @@
return checkQuickViewHtmlScrollY(await remoteCall.callRemoteTestUtil( return checkQuickViewHtmlScrollY(await remoteCall.callRemoteTestUtil(
'deepExecuteScriptInWebView', appId, [webView, getScrollY])); 'deepExecuteScriptInWebView', appId, [webView, getScrollY]));
}); });
// Check: no mimeType information is displayed. Note that there are multiple
// levels of shadow DOM present in this query.
const mimeTypeQuery = [
'#quick-view', '#dialog[open] files-metadata-box[metadata~="mime"]',
'files-metadata-entry[key="Type"]', '#box[hidden]'
];
await remoteCall.waitForElement(appId, mimeTypeQuery);
}; };
/** /**
...@@ -915,6 +981,10 @@ ...@@ -915,6 +981,10 @@
// Check: the <webview> body backgroundColor should be transparent black. // Check: the <webview> body backgroundColor should be transparent black.
chrome.test.assertEq('rgba(0, 0, 0, 0)', backgroundColor[0]); chrome.test.assertEq('rgba(0, 0, 0, 0)', backgroundColor[0]);
// Check: the correct mimeType should be displayed.
const mimeType = await getQuickViewMetadataBoxField(appId, 'Type');
chrome.test.assertEq('audio/ogg', mimeType);
}; };
/** /**
...@@ -1013,6 +1083,10 @@ ...@@ -1013,6 +1083,10 @@
'deepQueryAllElements', appId, [albumArtWebView, ['display']])); 'deepQueryAllElements', appId, [albumArtWebView, ['display']]));
}); });
// Check: the correct mimeType should be displayed.
const mimeType = await getQuickViewMetadataBoxField(appId, 'Type');
chrome.test.assertEq('audio/mpeg', mimeType);
// Check: the audio album metadata should also be displayed. // Check: the audio album metadata should also be displayed.
const album = await getQuickViewMetadataBoxField(appId, 'Album'); const album = await getQuickViewMetadataBoxField(appId, 'Album');
chrome.test.assertEq(album, 'OK Computer'); chrome.test.assertEq(album, 'OK Computer');
...@@ -1062,6 +1136,10 @@ ...@@ -1062,6 +1136,10 @@
// Check: the <webview> body backgroundColor should be transparent black. // Check: the <webview> body backgroundColor should be transparent black.
chrome.test.assertEq('rgba(0, 0, 0, 0)', backgroundColor[0]); chrome.test.assertEq('rgba(0, 0, 0, 0)', backgroundColor[0]);
// Check: the correct mimeType should be displayed.
const mimeType = await getQuickViewMetadataBoxField(appId, 'Type');
chrome.test.assertEq('image/jpeg', mimeType);
}; };
/** /**
...@@ -1208,6 +1286,10 @@ ...@@ -1208,6 +1286,10 @@
// Check: the Dimensions shown in the metadata box are correct. // Check: the Dimensions shown in the metadata box are correct.
const size = await getQuickViewMetadataBoxField(appId, 'Dimensions'); const size = await getQuickViewMetadataBoxField(appId, 'Dimensions');
chrome.test.assertEq('1324 x 4028', size); chrome.test.assertEq('1324 x 4028', size);
// Check: the correct mimeType should be displayed.
const mimeType = await getQuickViewMetadataBoxField(appId, 'Type');
chrome.test.assertEq('image/tiff', mimeType);
}; };
/** /**
...@@ -1361,6 +1443,10 @@ ...@@ -1361,6 +1443,10 @@
// Check: the <webview> body backgroundColor should be transparent black. // Check: the <webview> body backgroundColor should be transparent black.
chrome.test.assertEq('rgba(0, 0, 0, 0)', backgroundColor[0]); chrome.test.assertEq('rgba(0, 0, 0, 0)', backgroundColor[0]);
// Check: the correct mimeType should be displayed.
const mimeType = await getQuickViewMetadataBoxField(appId, 'Type');
chrome.test.assertEq('video/webm', mimeType);
// Close Quick View. // Close Quick View.
await closeQuickView(appId); await closeQuickView(appId);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment