Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dwds/lib/src/dwds_vm_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DwdsVmClient {
return {'result': Success().toJson()};
}
});
await client.registerService('hotRestart', 'WebDev fullReload');
await client.registerService('hotRestart', 'DWDS fullReload');

client.registerServiceCallback('fullReload', (_) async {
await chromeProxyService.tabConnection.page.enable();
Expand All @@ -65,15 +65,15 @@ class DwdsVmClient {
await chromeProxyService.tabConnection.sendCommand('Page.reload');
return {'result': Success().toJson()};
});
await client.registerService('fullReload', 'WebDev');
await client.registerService('fullReload', 'DWDS');

client.registerServiceCallback('ext.webdev.screenshot', (_) async {
client.registerServiceCallback('ext.dwds.screenshot', (_) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @jonahwilliams not sure if you were using this yet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't landed anything yet, so no issues here

await chromeProxyService.tabConnection.page.enable();
var response = await chromeProxyService.tabConnection.page
.sendCommand('Page.captureScreenshot');
return {'result': response.result};
});
await client.registerService('ext.webdev.screenshot', 'WebDev');
await client.registerService('ext.dwds.screenshot', 'DWDS');

return DwdsVmClient(client, requestController, responseController);
}
Expand Down
7 changes: 2 additions & 5 deletions dwds/test/debug_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

import 'dart:io';

import 'package:dwds/src/services/debug_service.dart';
import 'package:test/test.dart';

import 'fixtures/context.dart';

final context = TestContext();
DebugService get debugService => context.debugService;

void main() {
setUpAll(() async {
Expand All @@ -23,12 +21,11 @@ void main() {

test('Refuses connections without the auth token', () async {
expect(
WebSocket.connect(
'ws://${debugService.hostname}:${debugService.port}/ws'),
WebSocket.connect('ws://localhost:${context.debugConnection.port}/ws'),
throwsA(isA<WebSocketException>()));
});

test('Accepts connections with the auth token', () async {
expect(WebSocket.connect('${debugService.wsUri}/ws'), completes);
expect(WebSocket.connect('${context.debugConnection.wsUri}/ws'), completes);
});
}
51 changes: 21 additions & 30 deletions dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:build_daemon/data/build_status.dart';
import 'package:build_daemon/data/build_target.dart';
import 'package:dwds/dwds.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:dwds/src/services/debug_service.dart';
import 'package:dwds/src/utilities/shared.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as p;
Expand All @@ -23,14 +22,14 @@ import 'utilities.dart';

class TestContext {
String appUrl;
DebugService debugService;
ChromeProxyService get chromeProxyService =>
debugService.chromeProxyService as ChromeProxyService;
WipConnection tabConnection;
TestServer testServer;
BuildDaemonClient daemonClient;
WebDriver webDriver;
Process chromeDriver;
AppConnection appConnection;
DebugConnection debugConnection;
ChromeProxyService chromeProxyService;
int port;

/// Top level directory in which we run the test server..
Expand Down Expand Up @@ -64,15 +63,6 @@ class TestContext {

daemonClient = await connectClient(
workingDirectory, [], (log) => printOnFailure(log.toString()));
testServer = await TestServer.start(
'localhost',
port,
daemonPort(workingDirectory),
pathToServe,
ReloadConfiguration.none,
false,
daemonClient.buildResults,
);
daemonClient.registerBuildTarget(
DefaultBuildTarget((b) => b..target = pathToServe));
daemonClient.startBuild();
Expand All @@ -82,7 +72,6 @@ class TestContext {
.any((result) => result.status == BuildStatus.succeeded))
.timeout(Duration(seconds: 60));

appUrl = 'http://localhost:$port/$path';
var debugPort = await findUnusedPort();
var capabilities = Capabilities.chrome
..addAll({
Expand All @@ -92,33 +81,35 @@ class TestContext {
});
webDriver =
await createDriver(spec: WebDriverSpec.JsonWire, desired: capabilities);
await webDriver.get(appUrl);
var connection = ChromeConnection('localhost', debugPort);

testServer = await TestServer.start(
'localhost',
port,
daemonPort(workingDirectory),
pathToServe,
ReloadConfiguration.none,
false,
daemonClient.buildResults,
() async => connection,
);

appUrl = 'http://localhost:$port/$path';
await webDriver.get(appUrl);
var tab = await connection.getTab((t) => t.url == appUrl);
tabConnection = await tab.connect();
await tabConnection.runtime.enable();
await tabConnection.debugger.enable();

// Check if the app is already loaded, look for the top level
// `registerExtension` variable which we set as the last step.
var result = await tabConnection.runtime
.evaluate('(window.registerExtension !== undefined).toString();');
if (result.value != 'true') {
// If it wasn't already loaded, then wait for the 'Page Ready' log.
await tabConnection.runtime.onConsoleAPICalled.firstWhere((event) =>
event.type == 'debug' && event.args[0].value == 'Page Ready');
}
appConnection = await testServer.dwds.connectedApps.first;
debugConnection = await testServer.dwds.debugConnection(appConnection);

var assetHandler = (String path) async {
var result = await http.get('http://localhost:$port/$path');
return result.body;
};

var instanceId =
await tabConnection.runtime.evaluate(r'window.$dartAppInstanceId');

debugService = await DebugService.start(
'localhost', connection, assetHandler, instanceId.value.toString());
chromeProxyService = await ChromeProxyService.create(
connection, assetHandler, appConnection.request.instanceId);
}

Future<Null> tearDown() async {
Expand Down
7 changes: 5 additions & 2 deletions dwds/test/fixtures/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:dwds/dwds.dart';
import 'package:http_multi_server/http_multi_server.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:test/test.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

class TestServer {
final HttpServer _server;
Expand Down Expand Up @@ -46,6 +48,7 @@ class TestServer {
ReloadConfiguration reload,
bool startDevTools,
Stream<BuildResults> buildResults,
Future<ChromeConnection> Function() chromeConnection,
) async {
var pipeline = const Pipeline();

Expand All @@ -58,8 +61,8 @@ class TestServer {
applicationTarget: target,
assetServerPort: assetServerPort,
buildResults: filteredBuildResults,
chromeConnection: () async => null,
logWriter: (level, message) => print(message),
chromeConnection: chromeConnection,
logWriter: (level, message) => printOnFailure(message),
reloadConfiguration: reload,
serveDevTools: startDevTools,
verbose: true,
Expand Down
25 changes: 25 additions & 0 deletions dwds/test/screenshot_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';

import 'fixtures/context.dart';

final context = TestContext();

void main() {
setUpAll(() async {
await context.setUp();
});

tearDownAll(() async {
await context.tearDown();
});

test('can take screenshots', () async {
var response = await context.debugConnection.vmService
.callServiceExtension('ext.dwds.screenshot');
expect(response.json['data'], isNotNull);
});
}
60 changes: 0 additions & 60 deletions webdev/test/serve/screenshot_test.dart

This file was deleted.