[lighthouse] Add start view e2e tests

Merges generate-report_test.ts and indexeddb-warning_test.ts. Both of these test files are specific to the start view so it makes sense to consolidate.

Additional test cases migrated from the lighthouse-prevent-run.js web test.

Bug: None
Change-Id: Ib8c27ec64768deddac7ff093864e3854062a6a05
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3880222
Reviewed-by: Andres Olivares <andoli@chromium.org>
Commit-Queue: Adam Raine <asraine@chromium.org>
Reviewed-by: Paul Irish <paulirish@chromium.org>
diff --git a/test/e2e/helpers/lighthouse-helpers.ts b/test/e2e/helpers/lighthouse-helpers.ts
index 079ef14..7ecfa18 100644
--- a/test/e2e/helpers/lighthouse-helpers.ts
+++ b/test/e2e/helpers/lighthouse-helpers.ts
@@ -105,6 +105,11 @@
   return button.evaluate(element => (element as HTMLButtonElement).disabled);
 }
 
+export async function getHelpText() {
+  const helpTextHandle = await waitFor('.lighthouse-start-view-fr .lighthouse-help-text');
+  return helpTextHandle.evaluate(helpTextEl => helpTextEl.textContent);
+}
+
 export async function openStorageView() {
   await click('#tab-resources');
   const STORAGE_SELECTOR = '[aria-label="Storage"]';
diff --git a/test/e2e/lighthouse/BUILD.gn b/test/e2e/lighthouse/BUILD.gn
index ca346c1..2d132ec 100644
--- a/test/e2e/lighthouse/BUILD.gn
+++ b/test/e2e/lighthouse/BUILD.gn
@@ -6,10 +6,9 @@
 
 node_ts_library("lighthouse") {
   sources = [
-    "generate-report_test.ts",
-    "indexeddb-warning_test.ts",
     "navigation_test.ts",
     "request_blocking_test.ts",
+    "start-view_test.ts",
   ]
 
   deps = [
diff --git a/test/e2e/lighthouse/generate-report_test.ts b/test/e2e/lighthouse/generate-report_test.ts
deleted file mode 100644
index 4ca4d34..0000000
--- a/test/e2e/lighthouse/generate-report_test.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2020 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.
-
-import {assert} from 'chai';
-
-import {goToResource} from '../../shared/helper.js';
-import {describe, it} from '../../shared/mocha-extensions.js';
-import {isGenerateReportButtonDisabled, navigateToLighthouseTab} from '../helpers/lighthouse-helpers.js';
-
-describe('The Lighthouse Tab', async () => {
-  it('shows a button to generate a new report', async () => {
-    await navigateToLighthouseTab('empty.html');
-
-    const disabled = await isGenerateReportButtonDisabled();
-    assert.isFalse(disabled, 'The Generate Report button should not be disabled');
-  });
-
-  // Broken on non-debug runs
-  it.skip('[crbug.com/1057948] shows generate report button even when navigating to an unreachable page', async () => {
-    await navigateToLighthouseTab('empty.html');
-
-    await goToResource('network/unreachable.rawresponse');
-    const disabled = await isGenerateReportButtonDisabled();
-    assert.isTrue(disabled, 'The Generate Report button should be disabled');
-  });
-});
diff --git a/test/e2e/lighthouse/indexeddb-warning_test.ts b/test/e2e/lighthouse/indexeddb-warning_test.ts
deleted file mode 100644
index 45fb9d6..0000000
--- a/test/e2e/lighthouse/indexeddb-warning_test.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2022 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.
-
-import {assert} from 'chai';
-
-import {waitFor} from '../../shared/helper.js';
-import {describe, it} from '../../shared/mocha-extensions.js';
-import {clearSiteData, navigateToLighthouseTab, waitForStorageUsage} from '../helpers/lighthouse-helpers.js';
-
-describe('IndexedDB warning', async function() {
-  beforeEach(async function() {
-    // e2e tests in application/ create websql and indexeddb items and don't clean up after themselves
-    await clearSiteData();
-  });
-
-  it('displays when important data may affect performance', async () => {
-    await navigateToLighthouseTab('empty.html');
-
-    let warningElem = await waitFor('.lighthouse-warning-text.hidden');
-    const warningText1 = await warningElem.evaluate(node => node.textContent?.trim());
-    assert.strictEqual(warningText1, '');
-
-    await navigateToLighthouseTab('lighthouse/lighthouse-storage.html');
-    // Wait for storage state to lazily update
-    await waitForStorageUsage(quota => quota > 0);
-
-    warningElem = await waitFor('.lighthouse-warning-text:not(.hidden)');
-    const expected =
-        'There may be stored data affecting loading performance in this location: IndexedDB. Audit this page in an incognito window to prevent those resources from affecting your scores.';
-    const warningText2 = await warningElem.evaluate(node => node.textContent?.trim());
-    assert.strictEqual(warningText2, expected);
-  });
-});
diff --git a/test/e2e/lighthouse/start-view_test.ts b/test/e2e/lighthouse/start-view_test.ts
new file mode 100644
index 0000000..beb1286
--- /dev/null
+++ b/test/e2e/lighthouse/start-view_test.ts
@@ -0,0 +1,91 @@
+// Copyright 2022 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.
+
+import {assert} from 'chai';
+
+import {goTo, goToResource, waitFor} from '../../shared/helper.js';
+import {describe, it} from '../../shared/mocha-extensions.js';
+import {
+  clearSiteData,
+  getHelpText,
+  isGenerateReportButtonDisabled,
+  navigateToLighthouseTab,
+  selectCategories,
+  waitForStorageUsage,
+} from '../helpers/lighthouse-helpers.js';
+
+describe('The Lighthouse start view', async () => {
+  it('shows a button to generate a new report', async () => {
+    await navigateToLighthouseTab('empty.html');
+
+    const disabled = await isGenerateReportButtonDisabled();
+    const helpText = await getHelpText();
+    assert.isFalse(disabled, 'The Generate Report button should not be disabled');
+    assert.strictEqual(helpText, '');
+  });
+
+  it('disables the start button when no categories are selected', async () => {
+    await navigateToLighthouseTab('empty.html');
+
+    await selectCategories([]);
+
+    const disabled = await isGenerateReportButtonDisabled();
+    const helpText = await getHelpText();
+    assert.isTrue(disabled, 'The Generate Report button should be disabled');
+    assert.strictEqual(helpText, 'At least one category must be selected.');
+  });
+
+  it('enables the start button if only one category is selected', async () => {
+    await navigateToLighthouseTab('empty.html');
+
+    await selectCategories(['performance']);
+
+    const disabled = await isGenerateReportButtonDisabled();
+    const helpText = await getHelpText();
+    assert.isFalse(disabled, 'The Generate Report button should be enabled');
+    assert.strictEqual(helpText, '');
+  });
+
+  it('disables the start button for internal pages', async () => {
+    await navigateToLighthouseTab();
+    await goTo('about:blank');
+
+    const disabled = await isGenerateReportButtonDisabled();
+    const helpText = await getHelpText();
+    assert.isTrue(disabled, 'The Generate Report button should be disabled');
+    assert.strictEqual(
+        helpText,
+        'Can only audit HTTP/HTTPS pages and Chrome extensions. Navigate to a different page to start an audit.');
+  });
+
+  // Broken on non-debug runs
+  it.skip('[crbug.com/1057948] shows generate report button even when navigating to an unreachable page', async () => {
+    await navigateToLighthouseTab('empty.html');
+
+    await goToResource('network/unreachable.rawresponse');
+    const disabled = await isGenerateReportButtonDisabled();
+    assert.isTrue(disabled, 'The Generate Report button should be disabled');
+  });
+
+  it('displays warning if important data may affect performance', async () => {
+    // e2e tests in application/ create websql and indexeddb items and don't clean up after themselves
+    await clearSiteData();
+
+    await navigateToLighthouseTab('empty.html');
+
+    let warningElem = await waitFor('.lighthouse-warning-text.hidden');
+    const warningText1 = await warningElem.evaluate(node => node.textContent?.trim());
+    assert.strictEqual(warningText1, '');
+
+    await navigateToLighthouseTab('lighthouse/lighthouse-storage.html');
+    // Wait for storage state to lazily update
+    await waitForStorageUsage(quota => quota > 0);
+
+    warningElem = await waitFor('.lighthouse-warning-text:not(.hidden)');
+    const expected =
+        'There may be stored data affecting loading performance in this location: IndexedDB. Audit this page in an incognito window to prevent those resources from affecting your scores.';
+    const warningText2 = await warningElem.evaluate(node => node.textContent?.trim());
+    assert.strictEqual(warningText2, expected);
+  });
+});
diff --git a/test/webtests/http/tests/devtools/lighthouse/lighthouse-prevent-run-expected.txt b/test/webtests/http/tests/devtools/lighthouse/lighthouse-prevent-run-expected.txt
deleted file mode 100644
index ce53bfa..0000000
--- a/test/webtests/http/tests/devtools/lighthouse/lighthouse-prevent-run-expected.txt
+++ /dev/null
@@ -1,66 +0,0 @@
-Tests that audits panel prevents run of unauditable pages.
-
-
-
-**Prevents audit with no categories**
-
-========== Lighthouse Start Audit State ==========
-[ ] Performance
-[ ] Accessibility
-[ ] Best practices
-[ ] SEO
-[ ] Progressive Web App
-[ ] Publisher Ads
-[x] Legacy navigation
-[x] Clear storage
-Throttling method: simulate
-Help text: At least one category must be selected.
-Analyze page load: disabled visible
-
-
-**Allows audit with a single category**
-
-========== Lighthouse Start Audit State ==========
-[x] Performance
-[ ] Accessibility
-[ ] Best practices
-[ ] SEO
-[ ] Progressive Web App
-[ ] Publisher Ads
-[x] Legacy navigation
-[x] Clear storage
-Throttling method: simulate
-Analyze page load: enabled visible
-
-
-**Allows audit on undockable page**
-
-========== Lighthouse Start Audit State ==========
-[x] Performance
-[ ] Accessibility
-[ ] Best practices
-[ ] SEO
-[ ] Progressive Web App
-[ ] Publisher Ads
-[x] Legacy navigation
-[x] Clear storage
-Throttling method: simulate
-Analyze page load: enabled visible
-
-
-**Prevents audit on internal page**
-URL: about:blank
-
-========== Lighthouse Start Audit State ==========
-[x] Performance
-[ ] Accessibility
-[ ] Best practices
-[ ] SEO
-[ ] Progressive Web App
-[ ] Publisher Ads
-[x] Legacy navigation
-[x] Clear storage
-Throttling method: simulate
-Help text: Can only audit HTTP/HTTPS pages and Chrome extensions. Navigate to a different page to start an audit.
-Analyze page load: disabled visible
-
diff --git a/test/webtests/http/tests/devtools/lighthouse/lighthouse-prevent-run.js b/test/webtests/http/tests/devtools/lighthouse/lighthouse-prevent-run.js
deleted file mode 100644
index 74fbc62..0000000
--- a/test/webtests/http/tests/devtools/lighthouse/lighthouse-prevent-run.js
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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.
-
-(async function() {
-  // about:blank never fires a load event so just wait until we see the URL change
-  function navigateToAboutBlankAndWait() {
-    const listenerPromise = new Promise(resolve => {
-      self.SDK.targetManager.addEventListener(SDK.TargetManager.Events.InspectedURLChanged, resolve);
-    });
-
-    TestRunner.navigate('about:blank');
-    return listenerPromise;
-  }
-
-  TestRunner.addResult('Tests that audits panel prevents run of unauditable pages.\n');
-  await TestRunner.navigatePromise('resources/lighthouse-basic.html');
-
-  await TestRunner.loadTestModule('lighthouse_test_runner');
-  await TestRunner.showPanel('lighthouse');
-
-  TestRunner.addResult('\n\n**Prevents audit with no categories**');
-  LighthouseTestRunner.openStartAudit();
-  const containerElement = LighthouseTestRunner.getContainerElement();
-  const ensureDisabledNames = ['Performance', 'Accessibility', 'Best practices', 'SEO', 'Progressive Web App'];
-  const checkboxes = Array.from(containerElement.querySelectorAll('.checkbox'));
-  for (const checkbox of checkboxes) {
-    if (!ensureDisabledNames.includes(checkbox.textElement.textContent)) {
-      continue;
-    }
-
-    if (checkbox.checkboxElement.checked) {
-      checkbox.checkboxElement.click();
-    }
-  }
-  LighthouseTestRunner.dumpStartAuditState();
-
-  TestRunner.addResult('\n\n**Allows audit with a single category**');
-  for (const checkbox of checkboxes) {
-    if (checkbox.textElement.textContent !== 'Performance') {
-      continue;
-    }
-
-    checkbox.checkboxElement.click();
-  }
-  LighthouseTestRunner.dumpStartAuditState();
-
-  TestRunner.addResult('\n\n**Allows audit on undockable page**');
-  // Extension page and remote debugging previously caused crashes (crbug.com/734532)
-  // However, the crashes have been resolved, so these should now pass.
-  LighthouseTestRunner.forcePageAuditabilityCheck();
-  LighthouseTestRunner.dumpStartAuditState();
-
-  TestRunner.addResult('\n\n**Prevents audit on internal page**');
-  await navigateToAboutBlankAndWait();
-  TestRunner.addResult(`URL: ${TestRunner.mainTarget.inspectedURL()}`);
-  LighthouseTestRunner.dumpStartAuditState();
-
-  TestRunner.completeTest();
-})();