High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
Add integration tests for tabs and tabId parameters
Mario28f09a41bb89
diff --git a/tests/integration/main_test.go b/tests/integration/main_test.goindex f8ff4448..983afccc 100644--- a/tests/integration/main_test.go+++ b/tests/integration/main_test.go@@ -35,7 +35,7 @@ func TestMain(m *testing.M) {// Start servercmd := exec.Command("/tmp/pinchtab-test")-+// Build environment for subprocess// Start with a filtered set of inherited env vars, then add test-specific onesbaseEnv := os.Environ()@@ -46,7 +46,7 @@ func TestMain(m *testing.M) {env = append(env, e)}}-+// Add test-specific environmentenv = append(env,"BRIDGE_PORT="+port,@@ -56,18 +56,18 @@ func TestMain(m *testing.M) {fmt.Sprintf("BRIDGE_STATE_DIR=%s", mustTempDir()),fmt.Sprintf("BRIDGE_PROFILE=%s", mustTempDir()),)-+// Pass CHROME_BINARY if set by CI workflow or environmentif chromeBinary := os.Getenv("CHROME_BINARY"); chromeBinary != "" {env = append(env, "CHROME_BINARY="+chromeBinary)}-+// Pass BRIDGE_CHROME_VERSION if TEST_CHROME_VERSION is setif testChromeVersion := os.Getenv("TEST_CHROME_VERSION"); testChromeVersion != "" {fmt.Fprintf(os.Stderr, "TestMain: setting BRIDGE_CHROME_VERSION=%s from TEST_CHROME_VERSION\n", testChromeVersion)env = append(env, "BRIDGE_CHROME_VERSION="+testChromeVersion)}-+cmd.Env = envcmd.Stdout = os.Stdoutcmd.Stderr = os.Stderrdiff --git a/tests/integration/snapshot_test.go b/tests/integration/snapshot_test.goindex d6abb5e8..3f7cd9b8 100644--- a/tests/integration/snapshot_test.go+++ b/tests/integration/snapshot_test.go@@ -86,3 +86,55 @@ func TestSnapshot_MaxTokens(t *testing.T) {t.Fatalf("expected 200, got %d", code)}}++// S9: Snapshot with specific tabId+func TestSnapshot_WithTabId(t *testing.T) {+ // Create first tab and navigate to example.com+ code, body := httpPost(t, "/tab", map[string]string{+ "action": "new",+ "url": "https://example.com",+ })+ if code != 200 {+ t.Skip("could not create first tab")+ }+ var tab1Data map[string]any+ _ = json.Unmarshal(body, &tab1Data)+ tab1ID, ok := tab1Data["tabId"].(string)+ if !ok || tab1ID == "" {+ t.Skip("no tabId in response")+ }++ // Create second tab and navigate to httpbin.org+ code, body = httpPost(t, "/tab", map[string]string{+ "action": "new",+ "url": "https://httpbin.org",+ })+ if code != 200 {+ t.Skip("could not create second tab")+ }+ var tab2Data map[string]any+ _ = json.Unmarshal(body, &tab2Data)+ tab2ID, ok := tab2Data["tabId"].(string)+ if !ok || tab2ID == "" {+ t.Skip("no tabId in response")+ }++ // Get snapshot from tab2 (should contain httpbin content)+ code, body = httpGet(t, "/snapshot?tabId="+tab2ID)+ if code != 200 {+ t.Fatalf("expected 200 for /snapshot?tabId=%s, got %d", tab2ID, code)+ }+ snapshotText := string(body)+ // httpbin.org should have "httpbin" or "HTTP" in its snapshot+ if !strings.Contains(snapshotText, "httpbin") && !strings.Contains(snapshotText, "HTTP") {+ t.Error("expected httpbin-related content in tab2 snapshot")+ }+}++// S10: Snapshot with non-existent tabId+func TestSnapshot_NoTab(t *testing.T) {+ code, _ := httpGet(t, "/snapshot?tabId=nonexistent_xyz")+ if code == 200 {+ t.Errorf("expected error (400/404) for non-existent tab, got %d", code)+ }+}diff --git a/tests/integration/tabs_test.go b/tests/integration/tabs_test.goindex 5eab47cb..74a28829 100644--- a/tests/integration/tabs_test.go+++ b/tests/integration/tabs_test.go@@ -71,6 +71,14 @@ func TestTabs_Close(t *testing.T) {}}+// TB4: Close without tabId+func TestTabs_CloseWithoutTabId(t *testing.T) {+ code, _ := httpPost(t, "/tab", map[string]string{"action": "close"})+ if code != 400 {+ t.Errorf("expected 400 when closing without tabId, got %d", code)+ }+}+// TB5: Bad actionfunc TestTabs_BadAction(t *testing.T) {code, _ := httpPost(t, "/tab", map[string]string{"action": "explode"})@@ -78,3 +86,43 @@ func TestTabs_BadAction(t *testing.T) {t.Errorf("expected 400 for bad action, got %d", code)}}++// TB6: Max tabs - create many tabs and verify behavior+func TestTabs_MaxTabs(t *testing.T) {+ // Get initial tab count+ _, initialBody := httpGet(t, "/tabs")+ var initialResp map[string]any+ _ = json.Unmarshal(initialBody, &initialResp)+ initialTabs := len(initialResp["tabs"].([]any))++ // Try to create 20 tabs and verify they are created or error appropriately+ createdCount := 0+ for i := 0; i < 20; i++ {+ code, _ := httpPost(t, "/tab", map[string]string{+ "action": "new",+ "url": "https://example.com",+ })+ if code == 200 {+ createdCount+++ } else if code >= 400 {+ // Server returned an error (likely hit limit)+ break+ }+ }++ // Verify we created at least one tab or hit an error+ if createdCount == 0 && len(initialTabs) > 0 {+ // Acceptable: either we created tabs or hit limit immediately+ }++ // Get final tab count+ _, finalBody := httpGet(t, "/tabs")+ var finalResp map[string]any+ _ = json.Unmarshal(finalBody, &finalResp)+ finalTabs := finalResp["tabs"].([]any)++ // Verify tab list changed or was already at limit+ if len(finalTabs) < initialTabs {+ t.Error("expected tab count to not decrease")+ }+}diff --git a/tests/integration/text_test.go b/tests/integration/text_test.goindex e90f7a94..51cd7f78 100644--- a/tests/integration/text_test.go+++ b/tests/integration/text_test.go@@ -3,6 +3,7 @@package integrationimport (+ "encoding/json""strings""testing")@@ -32,3 +33,55 @@ func TestText_Raw(t *testing.T) {t.Error("expected 'Example Domain' in raw text")}}++// T3: Text with specific tabId+func TestText_WithTabId(t *testing.T) {+ // Create first tab and navigate to example.com+ code, body := httpPost(t, "/tab", map[string]string{+ "action": "new",+ "url": "https://example.com",+ })+ if code != 200 {+ t.Skip("could not create first tab")+ }+ var tab1Data map[string]any+ _ = json.Unmarshal(body, &tab1Data)+ tab1ID, ok := tab1Data["tabId"].(string)+ if !ok || tab1ID == "" {+ t.Skip("no tabId in response")+ }++ // Create second tab and navigate to httpbin.org+ code, body = httpPost(t, "/tab", map[string]string{+ "action": "new",+ "url": "https://httpbin.org",+ })+ if code != 200 {+ t.Skip("could not create second tab")+ }+ var tab2Data map[string]any+ _ = json.Unmarshal(body, &tab2Data)+ tab2ID, ok := tab2Data["tabId"].(string)+ if !ok || tab2ID == "" {+ t.Skip("no tabId in response")+ }++ // Get text from tab2 (should contain httpbin content)+ code, body = httpGet(t, "/text?tabId="+tab2ID)+ if code != 200 {+ t.Fatalf("expected 200 for /text?tabId=%s, got %d", tab2ID, code)+ }+ text := string(body)+ // httpbin.org should have "httpbin" in its content+ if !strings.Contains(text, "httpbin") && !strings.Contains(text, "HTTP") {+ t.Error("expected httpbin-related content in tab2 text")+ }+}++// T4: Text with non-existent tabId+func TestText_NoTab(t *testing.T) {+ code, _ := httpGet(t, "/text?tabId=nonexistent_xyz")+ if code == 200 {+ t.Errorf("expected error (400/404) for non-existent tab, got %d", code)+ }+}