blob: 28bc6a80950acedff322883002e35313e12482f8 [file] [view] [edit]
# dev.perfetto.GoogleDrive
Opens traces from Google Drive, either through the "Open from GDrive" sidebar
button (file picker) or through Drive's "Open with" deep link
(`?state=<json>`), and uploads the current trace to Google Drive through the
"Share to GDrive" sidebar button. The "Install Google Drive support" command
connects Perfetto to a Google account, which adds it to Drive's "Open with"
menu.
## Flows
### Sidebar flow (openFileFromSidebar / openFileById)
```mermaid
graph TD
A[Click Open from GDrive] --> B{Flow already running}
B -->|Yes| C[Do nothing]
B -->|No| D[Show Open from Google Drive dialog]
D -->|Browse Google Drive| E[Authenticate]
D -->|Paste Drive link and click Open| F[openFileById: same auth, download, and authorize flow as deep link]
E --> G{Got token}
G -->|No| H[Alert connect failed]
G -->|Yes| I[Show file picker]
I --> J{Picker result}
J -->|Cancelled| K[Do nothing]
J -->|Error| L[Alert picker failed]
J -->|Picked| M[Download file with omnibox progress]
M --> N{Download ok}
N -->|No| O[Alert download failed]
N -->|Yes| P[Open trace]
```
### Deep link flow (openFileFromDeeplink)
```mermaid
graph TD
A[Page loads with state param] --> B[Wait for clients to load]
B --> C{Clients loaded}
C -->|No| D[Alert Google Drive unavailable]
C -->|Yes| E[Parse state param]
E --> F{Valid}
F -->|No| G[Do nothing]
F -->|Yes| H[Authenticate]
H --> I{Popup blocked}
I -->|Yes| J[Prompt Connect to Google Drive]
J --> K{User pressed Connect}
K -->|No| L[Do nothing]
K -->|Yes| M[Authenticate again]
I -->|No| N{Got token}
M --> N
N -->|No| O[Alert connect failed]
N -->|Yes| P[Remove state param from URL]
P --> Q[Fetch metadata and download file with omnibox progress]
Q --> R{Access denied}
R -->|Yes| S{HideAuthDialog setting}
S -->|No| S1[Prompt Authorize access to file with Drive link]
S1 --> T{User pressed Authorize}
T -->|No| U[Do nothing]
T -->|Yes| V[Show picker for this file]
S -->|Yes| V
V --> W{Picker result}
W -->|Cancelled| X[Prompt File not shown in picker with Drive link]
X --> X1{User pressed Try Again}
X1 -->|No| X2[Do nothing]
X1 -->|Yes| V
W -->|Error| Y[Alert picker failed]
W -->|Picked| Z[Download file again with omnibox progress]
R -->|No| AA{Download ok}
Z --> AA
AA -->|No| AB[Alert download failed]
AA -->|Yes| AC[Open trace]
```
### Upload flow (uploadTraceToGDrive)
The buttons of the "Share to Google Drive" dialog each start a flow like this
one. Failures are not shown in a dialog of their own, which would replace the
share dialog: they are recorded in the trace's share state and shown in a
banner in the share dialog.
```mermaid
graph TD
A[Click Upload] --> B[Record upload in progress]
B --> C[Authenticate]
C --> D{Got token}
D -->|No| E[Record connect failed]
D -->|Yes| F{Cancelled meanwhile}
F -->|Yes| G[Do nothing]
F -->|No| H[Read back the trace contents]
H --> I{Contents available}
I -->|No| J[Record trace unavailable]
I -->|Yes| K[Upload with progress]
K --> L{Upload result}
L -->|Cancelled| M[Do nothing]
L -->|Error| N[Record upload failed]
L -->|Done| O{Apply default domain shares}
O -->|Yes| O1[Create domain permissions with allowFileDiscovery]
O1 --> O2{Permissions ok}
O2 -->|No| O3[Record default sharing failed]
O2 -->|Yes| O4[Fetch initial permissions]
O3 --> O4
O -->|No| O4
O4 --> O5[Record file ID as saved]
E --> P[Clear upload in progress]
G --> P
J --> P
M --> P
N --> P
O5 --> P
```
The other actions in the share dialog follow the same shape — authenticate, then
call Drive, recording any failure in the banner:
- **Location** (`pickUploadFolder`): opens the folder picker and remembers the
chosen folder in headless settings.
- **Share… / Edit sharing** (`openGDriveSharingDialog`): opens Drive's sharing
dialog. When it closes, permissions are refreshed (updating remembered default
domain shares) and any link-only domain permissions are made searchable
(`allowFileDiscovery: true`) on a best-effort basis (failing silently).
- **Refresh** (`refreshGDrivePermissions`): reloads current permissions (or
records `access_denied` on HTTP 403).
- **Make searchable** (`makeGDrivePermissionsSearchable`): enables
`allowFileDiscovery: true` on link-only domain permissions (never `anyone`)
and refreshes permissions.
### Authenticate step (GoogleOAuthClient authenticate)
Every "Authenticate" box above runs this. It never throws: every outcome is
returned as a Result.
```mermaid
graph TD
A[Authenticate called with a scope] --> B{Cached token covers the scope}
B -->|Yes| C{Token expired}
C -->|No| D[Return cached token]
C -->|Yes| E{Request for this scope already in flight}
B -->|No| E
E -->|Yes| F[Wait for that request and share its result]
E -->|No| G[Ask Google for a token via popup]
G --> H{Google response}
H -->|Token| N{Every requested scope granted}
N -->|Yes| I[Store token with its granted scopes and expiry of expires_in minus 60 seconds]
I --> J[Return new token]
N -->|No| O[Return error missing_scopes]
H -->|Popup failed to open| K[Return error popup_blocked]
H -->|Popup closed| L[Return error popup_closed]
H -->|Other error| M[Return error with cause]
```
### Scopes
Each action passes the OAuth scope it needs to `authenticate()`, one at a
time. There is no default:
| Scope | What it allows | Asked for by |
| --- | --- | --- |
| `drive.install` | Perfetto is offered in Drive's "Open with" menu. No access to files | The "Install Google Drive support" command |
| `drive.file` | Reading and creating the files the user opens or picks with Perfetto | Nothing yet: the flows that open files will ask for it |
Asking for one scope at a time matters. When an app asks for several together,
Google's consent screen shows a tick box for each and the user can refuse any
of them, and there is no way to mark one as required. A single scope is simply
allowed or cancelled. The client still checks which scopes were granted, and
returns `missing_scopes` if any that were asked for are missing.
## Content Security Policy
The UI's Content Security Policy (CSP) is set in
`setupContentSecurityPolicy()` in `ui/src/frontend/index.ts`. This plugin is
the reason for the entries below. They apply to every user of the UI, whether
or not they use Google Drive, so keep them as narrow as the plugin allows.
| Directive | Entry | Why it is needed |
| --- | --- | --- |
| `script-src` | `https://accounts.google.com/gsi/client` | Google Identity Services, which issues the access token |
| `script-src` | `https://apis.google.com/js/api.js` | The Google API loader |
| `script-src` | `https://apis.google.com/_/scs/abc-static/_/js/` | The modules the loader fetches (picker, sharing dialog) |
| `frame-src` | `https://docs.google.com/picker` and `/picker/` | The picker dialog |
| `frame-src` | `https://drive.google.com/sharing/` and `/drivesharing/` | The sharing dialog |
| `img-src` | `https://ssl.gstatic.com` | Icons used by the picker and sharing dialog |
Why the entries look the way they do:
- **Google's scripts cannot be bundled.** They are only served by Google and
change without notice, so they are loaded at runtime and need `script-src`
entries. The module URLs contain version hashes, so only their directory
can be named.
- **Paths, not hosts.** `*.google.com` was removed from `script-src` in #8176
because those hosts serve many other scripts. Each entry here names one
script, or one directory, instead.
- **No frame entry for connecting.** The plugin only uses the OAuth token
client, which opens a popup. Popups are not governed by `frame-src`, so
`accounts.google.com` is not listed there.
- **Drive requests need nothing extra.** They are plain `fetch()` calls to
`www.googleapis.com`, which `connect-src` already allows.
### Known limits
The path-based entries narrow the policy but are not a hard boundary. All of
the following need an HTML injection bug in the UI before they matter, and
none is known to allow arbitrary script execution.
- **Query strings are ignored by CSP.** `api.js` accepts an `onload`
parameter naming a global function to call once it has loaded. Injected
markup could use that to call a top-level global function, without
arguments. In production the service worker blocks external requests that
have a query string, which stops this once the worker controls the page.
That is not the case on localhost or on a first visit.
- **Paths are not checked after a redirect.** Once a request is redirected,
CSP only matches the host. A redirect that starts inside the module
directory and stays on `apis.google.com` is therefore allowed, so in
practice treat the whole of `apis.google.com` as allowed for scripts.
- **Every loader module is reachable,** not only the two the plugin uses, and
Google Identity Services can be driven from page markup (an element with
the id `g_id_onload`). Both could be used to call a global function by
name, or to show a Google sign-in prompt on this origin.
Moving `script-src` to hashes or nonces with `'strict-dynamic'` would remove
this whole class, as injected `<script>` tags would no longer run whichever
host they point at. That is a larger change to how the UI is served and has
not been done.
### When changing these entries
Run the flows under [No CSP violations](#no-csp-violations), and get the
change reviewed by someone on the security side.
## Manual testing
Keep this list up to date when adding a flow or a failure mode.
### What to test
Each of these links to a section below. When testing a change, copy this list
into the PR description as a checklist rather than ticking it off here.
Happy paths:
- [Install Google Drive support](#install-google-drive-support)
- [Sidebar flow](#sidebar-flow)
- [Token reuse within a session](#token-reuse-within-a-session)
- ["Open with" deep link](#open-with-deep-link)
- [Resource key](#resource-key)
- [Drive traces are not shareable](#drive-traces-are-not-shareable)
Sharing:
- [Upload the current trace](#upload-the-current-trace)
- [Cancel an upload](#cancel-an-upload)
- [Sidebar button state](#sidebar-button-state)
- [Close the dialog while uploading](#close-the-dialog-while-uploading)
- [Close the trace while uploading](#close-the-trace-while-uploading)
- [Choose a folder](#choose-a-folder)
- [After uploading](#after-uploading)
- [Share link](#share-link)
- [Sharing failures](#sharing-failures)
Button state:
- [Button state](#button-state)
- [Initialisation fails](#initialisation-fails)
- [Plugin disabled](#plugin-disabled)
Failure modes:
- [Popup blocked](#popup-blocked-connect-to-google-drive-dialog)
- [Connection failure](#connection-failure-couldnt-connect-to-google-drive-dialog)
- [Google popup closed](#google-popup-closed)
- [File not yet authorised](#file-not-yet-authorised-authorize-access-to-file-dialog)
- [Initialisation fails, with a deep link](#initialisation-fails)
- [Invalid deep link payload](#invalid-deep-link-payload)
- [Download failures](#download-failures)
- [Picker failures](#picker-failures)
Content Security Policy:
- [No CSP violations](#no-csp-violations)
### Setup
1. Run `ui/run-dev-server` and open `http://localhost:10000`.
2. The plugin is not enabled by default. Open
`http://localhost:10000/#!/plugins`, enable `dev.perfetto.GoogleDrive` and
reload.
3. `http://localhost:10000` must be an authorised JavaScript origin on the
OAuth client named in the config. If the picker works locally, it is.
4. The access token is only kept in memory, so every page load starts
disconnected.
5. Everything Google Drive support needs is loaded once, on every page load:
the config and Google's scripts. See
[Initialisation fails](#initialisation-fails).
Every "I give up" dialog (connection, picker and download failures) has an
"OK" button only, and no retry. Where there is an underlying error, it is
shown in a collapsed "Error details" section of the dialog rather than logged
to the console.
Two DevTools techniques are used below:
- **Block a request:** in the Network tab, right-click a request and choose
"Block request URL" (or add a pattern in the "Network request blocking"
drawer tab), then reload.
- **Build a deep link:** see ["Open with" deep link](#open-with-deep-link).
### Install Google Drive support
The "Install Google Drive support" command asks for permission to add
Perfetto to the "Open with" menu in the user's Google Drive. It does not ask
for access to any files.
1. Open the command palette (Ctrl/Cmd+Shift+P) and run "Install Google Drive
support".
2. Complete the Google popup. It should ask only for permission to connect
Perfetto to Google Drive, with no tick boxes and no mention of files. A
"Google Drive support installed" dialog should appear.
3. Run the command again without reloading: the dialog should appear straight
away, with no Google popup.
4. Close the Google popup instead of completing it: the "Couldn't connect to
Google Drive" dialog should appear, see
[Google popup closed](#google-popup-closed).
5. With initialisation failing (see
[Initialisation fails](#initialisation-fails)), the command should show the
"Google Drive unavailable" dialog.
### Sidebar flow
1. Click "Open from GDrive" in the sidebar. The "Open from Google Drive"
dialog should appear with two options: browsing Drive or pasting a Drive
link.
2. Click "Browse Google Drive", complete the Google popup if it asks, and pick
a trace in the picker. While downloading, progress should be shown in the
omnibox, and the trace should open titled with the file's name.
3. Cancel the picker instead of picking: nothing should happen.
4. Reopen the dialog, paste a Google Drive file link (or `?resourcekey=` link)
into the link field, and click "Open". It should follow the same download
and authorization flow as a deep link.
5. Clicking the sidebar button again while a flow is still running (e.g. while
the picker is open) should do nothing.
### Token reuse within a session
1. Complete the sidebar flow once.
2. Without reloading, click "Open from GDrive" again.
3. The picker should open straight away, with no Google popup.
The token is reused until about a minute before it expires (normally an hour).
After that, or after a page reload, the Google popup is needed again.
### "Open with" deep link
Drive opens the UI with a `state` query parameter naming the file. To
reproduce that without going through Drive, paste a URL like this into the
address bar of a new tab:
```
http://localhost:10000/?state=%7B%22ids%22%3A%5B%22<FILE_ID>%22%5D%2C%22action%22%3A%22open%22%7D
```
That is `{"ids":["<FILE_ID>"],"action":"open"}` URL-encoded. Take `<FILE_ID>`
from a Drive link (`https://drive.google.com/file/d/<FILE_ID>/view`).
Expected:
1. Unless popups are allowed for the site, the "Connect to Google Drive"
dialog appears first, see
[Popup blocked](#popup-blocked-connect-to-google-drive-dialog).
2. Once connected, the trace loads, titled with the file's real name. The
deep link only carries the file ID, so the name is looked up from Drive
with a separate metadata request, in parallel with the download.
3. The `state` parameter is removed from the address bar once connected. It
stays if the user cancels the "Connect to Google Drive" dialog or
connecting fails, so reloading retries the deep link.
If the name lookup fails the trace should still open, titled "Google Drive
file", and a warning is logged to the console. To check, block
`*fields=name*` in DevTools and load the deep link again.
#### From a real "Open with" click
The app is registered with Google Drive as an "Open with" app, so the real
flow can be tested too:
1. Connect through the UI at least once (e.g. with the sidebar flow).
Granting access is what adds Perfetto to your Drive's "Open with" menu.
2. In Drive, right-click a trace, choose "Open with" and pick Perfetto. Drive
opens the registered URL with a `state` parameter for that file.
3. To land on a local build instead of the registered URL, use a redirect
extension (e.g. Requestly) to rewrite the registered URL to
`http://localhost:10000/`, keeping the query string.
A file opened this way should already be authorised, so it should load without
the "Authorize access to file" dialog.
### Resource key
Some link-shared files need a resource key as well as the file ID. Their links
look like `.../file/d/<FILE_ID>/view?resourcekey=<KEY>`. To test one, use a
file you do not own and have not opened before, and add the key to the state
payload:
```json
{"ids":["<FILE_ID>"],"action":"open","resourceKeys":{"<FILE_ID>":"<KEY>"}}
```
URL-encode it and load it as the `state` parameter. In the DevTools Network
tab, the Drive download and metadata requests should carry the header
`X-Goog-Drive-Resource-Keys: <FILE_ID>/<KEY>`.
### Drive traces are not shareable
Drive traces are access-controlled, so they must not be uploaded to the public
permalink bucket.
1. Open a trace from Drive by either route.
2. The UI should not offer to create a permalink for it. (The "Share to
GDrive" button is separate: for a trace opened from Drive it shows "Saved
to GDrive", see [After uploading](#after-uploading).)
### Button state
The plugin is not enabled by default for anyone. Once it is enabled, the
"Open from GDrive" button is shown to every user, just below "Open trace
file". It is disabled (struck through) until initialisation has succeeded:
the config and Google's scripts all loaded. That happens shortly after
startup. Clicking the button while it is disabled says why.
To test, enable the plugin and reload:
1. For a moment after the page loads the button may be disabled. Clicking it
then should say that Google Drive support is still loading.
2. Once initialisation finishes the button should be enabled.
### Initialisation fails
On every page load the plugin loads, in order:
1. the config (API key, client ID and app ID), from
`https://storage.googleapis.com/perfetto-misc/gdrive_config.json`,
2. Google's sign-in library, from `https://accounts.google.com/gsi/client`,
3. Google's API loader script, from `https://apis.google.com/js/api.js`,
4. the picker and sharing dialog modules, also from `apis.google.com`.
None of this opens a popup. If any step fails, "Failed to initialize Google
Drive" is logged to the console (with the failing step as its cause) and the
sidebar buttons stay disabled. Nothing else is shown: no error dialog, as
this runs for every user on every load.
For each of the URLs above in turn:
1. Block it and reload.
2. The "Open from GDrive" button should stay disabled, and clicking it
should say that Google Drive support could not be loaded. The console
should show "Failed to initialize Google Drive".
3. Load a deep link URL with the request still blocked. A "Google Drive
unavailable" dialog should appear, and the `state` parameter should stay in
the address bar.
4. Unblock the URL and reload the same deep link. It should now proceed.
Also check that with everything blocked the rest of the UI works normally,
e.g. opening a local trace.
The config fetch times out after 5 seconds, and each of the other steps after
30 seconds. Until initialisation finishes, a deep link shows nothing. A failed
initialisation is not retried until the page is reloaded.
### Plugin disabled
The plugin is not enabled by default, so this is the state on a fresh profile.
1. Open `http://localhost:10000/#!/plugins`, make sure
`dev.perfetto.GoogleDrive` is disabled, then reload.
2. The "Open from GDrive" button should not appear.
3. In the DevTools Network tab there should be no requests for the config or
for Google's scripts (see [Initialisation fails](#initialisation-fails) for
the URLs).
4. Loading a deep link URL should do nothing.
5. Re-enable the plugin afterwards.
### Popup blocked ("Connect to Google Drive" dialog)
This only happens on a deep link: the sidebar flow starts from a click, so the
browser allows the popup.
1. Make sure popups are not set to "Allow" for `localhost:10000`
(`chrome://settings/content/popups`).
2. Load the deep link URL and do not click anything while it loads.
3. The "Connect to Google Drive" dialog should appear, including a hint that
allowing pop-ups for the site skips this step.
4. Click "Connect". The Google popup should open, and once it completes the
trace should load without a page reload.
5. Repeat and click "Cancel" instead. The dialog should close and nothing else
should happen.
6. Set popups to "Allow" for `localhost:10000` and load the deep link again.
The dialog should not appear; the Google popup should open by itself.
After "Connect" the popup is opened shortly after the click rather than inside
it, which Chrome allows. Other browsers may block it again, in which case the
"Couldn't connect to Google Drive" dialog appears saying the popup was
blocked.
### Connection failure ("Couldn't connect to Google Drive" dialog)
This is shown when Google reports an error while connecting, for example
because the user refuses to grant access.
1. Use a Google account that has not yet granted Perfetto access to Drive (or
remove Perfetto's access from the account's third-party access page first).
2. Click "Open from GDrive", or load the deep link URL.
3. On Google's consent screen, press "Cancel" rather than granting access.
4. The "Couldn't connect to Google Drive" dialog should appear with Google's
error, and the same error under "Error details", rather than the generic
crash dialog.
5. "OK" dismisses it and ends the flow. Start again from the sidebar button or
by reloading the deep link.
### Google popup closed
1. Set popups to "Allow" for `localhost:10000`, or start from the sidebar
button.
2. When the Google popup opens, close it without completing it.
3. The "Couldn't connect to Google Drive" dialog should appear, saying the
window was closed. There is no "Error details" section for this case.
4. "OK" dismisses it and ends the flow. Clicking the sidebar button again
should reopen the popup; reloading a deep link should retry it.
### File not yet authorised ("Authorize access to file" dialog)
The app can only read files the user has opened or picked with it.
1. Set popups to "Allow" for `localhost:10000`.
2. Load the deep link URL with the ID of a file that has never been opened or
picked through this app.
3. The download should fail with HTTP 403 or 404 and the "Authorize access to
file" dialog should appear.
4. Click "Authorize File Access". The dialog closes and the picker opens,
showing only that file. Pick it, and the trace should open, titled with the
file's real name.
5. Repeat and click "Cancel" in the dialog: the flow should end silently.
6. Repeat and cancel the picker instead of picking the file: a recovery dialog
should appear explaining why the file may not have been shown, with a direct
link to open it in Google Drive and a "Try Again" button that reopens the
picker.
Drive reports a file the app has not been granted as "not found", the same as
a file that does not exist. So a deep link with a made-up file ID also shows
this dialog; the picker it opens will then have nothing to pick.
### Invalid deep link payload
Each of these should be ignored silently: no dialog, no Google popup, and the
`state` parameter left in the address bar.
- `?state=not-json`
- `?state=%7B%22ids%22%3A%22abc%22%7D` (`ids` is not an array)
- `?state=%7B%22ids%22%3A%5B%5D%7D` (no file ID)
- A file ID or resource key containing anything other than letters, digits,
`_` and `-`, e.g. `{"ids":["../x"]}`.
This assumes initialisation succeeded. The payload is only parsed after the
clients have loaded, so if initialisation fails any `state` parameter, valid
or not, shows the "Google Drive unavailable" dialog.
### Download failures
The easiest way to make only the download fail is to block
`*googleapis.com/drive/v3/files/*alt=media*` in DevTools: connecting, the
picker and the name lookup still work.
A failed download shows a "Couldn't open <file name> from Google Drive" dialog
(or "Couldn't open file from Google Drive" if the name is not known), with the
underlying error under "Error details".
The one exception is when Drive refuses access to the file (HTTP 403 or 404)
on a deep link: that shows the "Authorize access to file" dialog instead, see
[File not yet authorised](#file-not-yet-authorised-authorize-access-to-file-dialog).
On the sidebar flow a 403 or 404 is just a failed download.
- **Sidebar flow** (block the pattern, then pick a file): the failure dialog
should appear.
- **Deep link, for an already authorised file** (block the pattern, then load
the deep link): the failure dialog should appear, titled with the file's
name, not the "Authorize access to file" dialog.
- **Deep link, the download after authorising fails** (load a deep link for a
file not yet authorised, click "Authorize File Access", and block the
pattern while the picker is showing, before picking the file): the failure
dialog should appear.
### Picker failures
Cancelling or closing the picker is not a failure: from the sidebar nothing
happens, and on a deep link a recovery dialog is shown with a link to open the
file in Google Drive and a "Try Again" button to reopen the picker.
If the picker cannot be built or reports an error, a "Couldn't open the Google
Drive file picker" dialog should appear, with the error under "Error details".
The picker's code is loaded during initialisation, so blocking requests
afterwards does not trigger this. To simulate it, run this in the DevTools
console after the page has loaded, then click "Open from GDrive":
```js
google.picker.PickerBuilder = class {
constructor() {
throw new Error('Simulated picker failure');
}
};
```
### Upload the current trace
The "Share to GDrive" button is in the sidebar's current trace section. It
is disabled under the same conditions as "Open from GDrive", see
[Button state](#button-state). It is also disabled for traces whose contents
cannot be read back to upload, such as one loaded from
`trace_processor_shell --httpd`; clicking it says why.
1. Open a trace from a local file.
2. Click "Share to GDrive". The "Share to Google Drive" dialog should open
with the file name filled in and focused, and "My Drive" (or the last
chosen folder) as the location. If you previously shared a trace with a
domain, an "Also share with <domain>" checkbox is shown and checked by
default.
3. Clear the file name: "Upload" should be disabled and the field outlined in
red. Type a name again.
4. Click "Upload" (or press Enter). Complete the Google popup if it asks.
While it uploads, a linear progress bar and status text should count up,
e.g. "Uploading… 42% (12.3 of 29.4 MB)". Use a large trace or DevTools
Network throttling to make this last long enough to see.
5. The dialog should switch to the saved view (showing the file name,
"Saved to Google Drive", and current permissions), and the file should
appear in Drive under that name.
6. Repeat with a large trace (hundreds of MB). The upload is sent as a single
request rather than with Drive's resumable upload; this has been seen to
work with a 600 MB trace.
### Cancel an upload
1. Start an upload that takes a while (large trace or DevTools Network
throttling).
2. Click "Cancel", which only appears while uploading. The upload should
stop, the form should return to normal with no error banner, and no file
should appear in Drive.
3. Click "Upload" again: it should start a fresh upload.
4. Click "Upload" and then "Cancel" while the Google popup is still open,
then complete the popup: nothing should be uploaded.
### Sidebar button state
The "Share to GDrive" button reflects what is happening, so an upload can be
followed with the dialog closed. Clicking it always opens the dialog.
| State | Text | Icon | Badge |
|---|---|---|---|
| Not uploaded | Share to GDrive | `add_to_drive` | preview |
| Uploading | Share to GDrive | `add_to_drive` | `…`, then a percentage |
| In Drive | Saved to GDrive | `cloud_done` | preview |
| Last action in the dialog failed | Share to GDrive | `error` | preview |
1. Start an upload that takes a while and close the dialog. The badge should
count up.
2. When it finishes, the button should change to "Saved to GDrive" with the
`cloud_done` icon.
3. Make an upload fail (see [Sharing failures](#sharing-failures)). The icon
should change to `error`, and back once an upload succeeds.
4. Open a trace from Drive: the button should show "Saved to GDrive" from the
start.
### Close the dialog while uploading
The dialog's state is kept with the trace, not with the dialog, so closing it
does not stop or hide an upload.
1. Start an upload that takes a while, then close the dialog (Escape, or its
close button).
2. Reopen it with "Share to GDrive" while the upload is still running. It
should show the upload in progress, with the count still moving, the name
and location fields disabled, and "Cancel" working. It should not offer a
second "Upload".
3. Close it again and wait for the upload to finish, then reopen it: it should
show "Saved to Google Drive".
4. Repeat, but make the upload fail while the dialog is closed (go offline in
DevTools). Reopening it should show the red banner.
5. Type a different file name, close the dialog without uploading, and reopen
it: the name you typed should still be there.
### Close the trace while uploading
1. Start an upload that takes a while, then open a different trace (or close
the current one).
2. The upload should be cancelled: in the DevTools Network tab the upload
request should show as cancelled, and no file should appear in Drive.
3. The newly opened trace should show as not uploaded, with no progress on its
"Share to GDrive" button.
### Choose a folder
1. In the dialog, click the location button ("My Drive"). Complete the Google
popup if it asks. The Google folder picker should open, titled "Select
folder".
2. Pick a folder: the location button should show its name with a reset icon
beside it, the choice is remembered for future uploads, and the upload
should go there.
3. Click the reset icon beside the location button: it should return to
"My Drive".
4. Click the location button again and cancel the picker: the location should
not change, and no banner should appear.
5. Pick a folder inside a shared drive (under "Shared drives" in Drive, as
opposed to "My Drive") and upload: the file should appear there. Opening a
trace that lives in a shared drive should work too.
### After uploading
With the dialog showing the saved state:
1. "People with access" and "General access" list the file's current
permissions (or a message if you do not have permission to view them). The
refresh icon reloads them from Drive.
2. If only you have access, a warning explains that recipients won't be able
to open the link until you share it, and the primary button is "Share…".
3. "Share…" (or "Edit sharing" once shared) opens Google Drive's sharing
dialog for the file. When you close it, permissions refresh automatically,
domain shares are remembered for future uploads, and any link-only domain
share is made searchable (`allowFileDiscovery: true`) on a best-effort
basis.
4. If a link-only domain permission remains unsearchable, a warning is shown
with a "Make searchable" button. If a link-only `anyone` permission is set,
the warning is shown without a "Make searchable" button (link-shared public
files are never made web-searchable).
5. "Copy Perfetto link" should copy a Perfetto link and briefly show "Copied".
6. "Open in Drive" should open the file in Drive in a new tab.
7. Close and reopen the dialog: it should still show the saved state.
8. Open a trace from Drive (sidebar or deep link), then click "Share to
GDrive": it should show the saved state straight away, without uploading,
and load its permissions.
### Share link
"Copy Perfetto link" produces a `?state=...` deep link of the form
`<origin>/?state=%7B%22ids%22%3A%5B%22<FILE_ID>%22%5D%7D`.
1. Paste it into a new tab. It should behave like the
["Open with" deep link](#open-with-deep-link): connect (with the "Connect
to Google Drive" dialog first unless popups are allowed), then the trace
loads with its real name.
2. Open it as a different Google account that the file has been shared with.
The "Authorize access to file" dialog should appear, see
[File not yet authorised](#file-not-yet-authorised-authorize-access-to-file-dialog).
3. With initialisation failing (see
[Initialisation fails](#initialisation-fails)), it should show the "Google
Drive unavailable" dialog.
### Sharing failures
Failures in the share dialog are shown in a red banner at the top of the
dialog, not in a separate dialog, so the file name and location are kept.
Where there is an underlying error it is under "Error details" in the banner.
The banner clears when the next action starts, and the user retries by
pressing the same button again.
- **Upload fails:** block `*upload/drive/v3/files*` in DevTools and click
"Upload". The banner should say the trace could not be uploaded, and
"Upload" should be usable again.
- **Drive rejects the upload:** e.g. a full Drive. The banner's error details
should include Drive's explanation and the HTTP status. Not easy to
provoke.
- **Connection fails:** click "Upload", "Change" or "Share" and press
"Cancel" on Google's consent screen (with an account that has not granted
access yet). The banner should say connecting to Google Drive failed.
- **Google popup closed:** click "Upload" and close the Google popup. The
banner should say the window was closed. Clicking "Upload" again should
reopen the popup.
- **Folder picker or sharing dialog fails:** not easy to provoke. The banner
should say the folder picker or sharing dialog could not be opened.
### No CSP violations
The Google dialogs are only allowed by specific Content Security Policy
entries, see [Content Security Policy](#content-security-policy). If one is
missing the dialog does not appear, or appears blank, and the browser logs
the reason.
1. Open DevTools and keep the Console visible. Reload the page.
2. Run each of these, and check that the dialog renders fully, icons
included:
- the [Sidebar flow](#sidebar-flow), through the Google popup and the
picker;
- the ["Open with" deep link](#open-with-deep-link), including the
"Authorize access to file" picker;
- [Upload the current trace](#upload-the-current-trace), then
[Choose a folder](#choose-a-folder) and "Share" from
[After uploading](#after-uploading).
3. The console should show no message starting "Refused to" (for example
"Refused to frame ..." or "Refused to load the script ...") that mentions
a Google host.